Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Adaptation doesn't respect Liskov invariance

#5

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.

Reported by Daniele Varrazzo · November 2nd, 2010 @ 12:12 AM

State: resolved
Milestone: release-2.3.0
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • 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.

    November 9th, 2010 @ 12:40 AM