SQLAlchemy: return existing object instead of creating a new on when calling constructor
There is exactly this example on the wiki at http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject.
Though, more recently I've preferred to use a @classmethod
for this instead of redefining the constructor, as explicit is better than implicit, also simpler:
user.email = Email.as_unique('[email protected]')
(I'm actually going to update the wiki now to more fully represent the usage options here.)