This project is archived and is in readonly mode.

#5 ✓resolved
Daniele Varrazzo

Adaptation doesn't respect Liskov invariance

Reported by Daniele Varrazzo | November 2nd, 2010 @ 12:12 AM | in release-2.3.0

An object can't be adapted even if one of its superclasses can: this breaks the Liskov invariance as the subclass is expected to behave like the superclass. In practice, for instance, if s.b. defines a string subclass, it is likely he wants it to be serialized in the database as a string. Currently psycopg raises a "can't adapt" (at least now it tells the class, so debugging is easier).

Proposal: if an object b of type B can't be adapted (it would be an error right now), walk its type's MRO and, if an adapter f for a supertype A is found, register the same adapter f for B too. If possible, detect the scope in which the adapter is registered for A (global, connection, cursor) and register the f as adapter for B in the same scope.

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo November 9th, 2010 @ 12:40 AM

    • State changed from “new” to “resolved”
    • Milestone set to release-2.3.0
    • Milestone order changed from “2” to “0”

    Feature implemented. Not released in 2.3.0-beta1, but it should in the next release.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins

People watching this ticket

Referenced by

Pages