[Sqlalchemy-tickets] Issue #4178: ORM reconstructor does not trigger when decorating an __init__ me
Brought to you by:
zzzeek
From: Joël P. <iss...@bi...> - 2018-02-02 03:40:50
|
New issue 4178: ORM reconstructor does not trigger when decorating an __init__ method https://bitbucket.org/zzzeek/sqlalchemy/issues/4178/orm-reconstructor-does-not-trigger-when Joël Perras: As mentioned in the [documentation](http://docs.sqlalchemy.org/en/latest/orm/constructors.html?highlight=reconstructor#constructors-and-object-initialization): > Any method may be tagged as the orm.reconstructor(), even the `__init__` method itself. This, however, does not appear to be the case. I've provided a simple test case based on existing reconstructor tests in `test/orm/test_mapper.py`, shown here as a diff against the current master branch (`399988aaed401ea6fc69aa580b9b71c236a30f16`). ``` #!diff diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index 42d114f6f..5f5ed11b9 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -1652,6 +1652,25 @@ class MapperTest(_fixtures.FixtureTest, AssertsCompiledSQL): create_session().query(User).first() eq_(recon, ['go']) + def test_reconstructor_init(self): + + users = self.tables.users + + recon = [] + + class User(object): + + @reconstructor + def __init__(self): + recon.append('go') + + mapper(User, users) + + User() + eq_(recon, []) + create_session().query(User).first() + eq_(recon, ['go']) + ``` I attempted to trace down why this was occurring in `orm.mapper.Mapper._configure_class_instrumentation`, but some of the indirection with regards to load events is more opaque to my limited understanding of how the mapper works than I'd like. This is clearly not a major bug, since the workaround is relatively simple, but wanted to flag it. |