[Sqlalchemy-tickets] Issue #3837: Feature Request: Extensible automap classes (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: 200 B. G. <iss...@bi...> - 2016-10-23 23:07:27
|
New issue 3837: Feature Request: Extensible automap classes https://bitbucket.org/zzzeek/sqlalchemy/issues/3837/feature-request-extensible-automap-classes 200 Billion Galaxies: Currently, automapped classes cannot be extended and used without error. Example: ``` #!python Base = automap_base() engine = create_engine(DATABASE_URL) Base.prepare(engine, reflect=True) ItemModelBase = Base.classes.item class DumbMixin: def some_helpful_method(self): print(self.id) class Item(DumbMixin, ItemModelBase): def lifetime(self): return self.updated - self.created item = Item() item.name = 'Just a test item.' ###################################################################### # Error stacktrace: Traceback (most recent call last): File "sqlalchemy/sql/elements.py", line 676, in __getattr__ return getattr(self.comparator, key) AttributeError: 'Comparator' object has no attribute '_supports_population' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "sqlalchemy/orm/attributes.py", line 185, in __getattr__ return getattr(self.comparator, key) File "sqlalchemy/util/langhelpers.py", line 840, in __getattr__ return self._fallback_getattr(key) File "sqlalchemy/orm/properties.py", line 267, in _fallback_getattr return getattr(self.__clause_element__(), key) File "sqlalchemy/sql/elements.py", line 682, in __getattr__ key) AttributeError: Neither 'AnnotatedColumn' object nor 'Comparator' object has an attribute '_supports_population' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "sqlalchemy/orm/attributes.py", line 234, in __get__ if self._supports_population and self.key in dict_: File "sqlalchemy/orm/attributes.py", line 193, in __getattr__ key) AttributeError: Neither 'InstrumentedAttribute' object nor 'Comparator' object associated with item.name has an attribute '_supports_population' ``` It would be great if we could have our cake and eat it too. A healthy mix of automapped and declarative bases means I can use `alembic` to manage my migrations, and just have the classes update without having to maintain essentially two schema definitions. If this is already doable and I'm just missing something, I'd love to be enlightened. |