Mapper property all_orm_descriptors memoized even after new attributes get added
The following code should outline the issue:
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base, synonym_for
Base = declarative_base()
class Article(Base):
__tablename__ = 'article'
id = sa.Column(sa.Integer, primary_key=True)
Article.__mapper__.all_orm_descriptors
Article.name = sa.Column(sa.String)
Article.__mapper__.all_orm_descriptors.keys()
I would expect the last line to return a list containing 'name'
, but currently it only returns ['id', '__mapper__']
. Even calling sa.orm.configure_mappers()
won't help here.
I noticed this problem when I had SQLAlchemy mapper configuration listeners that were accessing Mapper.all_orm_descriptors
.
Comments (5)
-
repo owner -
repo owner -
reporter Yeah it works! Thanks for very fast response Mike =)
Edit: it works after
sa.orm.configure_mappers()
is called. Just to clarify if anyone else is encountering this issue. -
repo owner - changed status to resolved
Use configured props for mapper.attrs, mapper.all_orm_descriptors
Fixed bug where the :attr:
.Mapper.attrs
, :attr:.Mapper.all_orm_descriptors
and other derived attributes would fail to refresh when mapper properties or other ORM constructs were added to the mapper/class after these accessors were first called.(also trying different ways to get the changelog to merge cleanly)
Change-Id: Iaecdb4b3d8c3a3b44302a5880476e60a1f4e27d9 Fixes:
#3778→ <<cset f2eb4aac9517>>
-
repo owner Use configured props for mapper.attrs, mapper.all_orm_descriptors
Fixed bug where the :attr:
.Mapper.attrs
, :attr:.Mapper.all_orm_descriptors
and other derived attributes would fail to refresh when mapper properties or other ORM constructs were added to the mapper/class after these accessors were first called.Change-Id: Iaecdb4b3d8c3a3b44302a5880476e60a1f4e27d9 Fixes:
#3778(cherry picked from commit 6319eb0ce7c095ba7d4f60746ce12cf575730b46)→ <<cset 8b64240e3a2c>>
- Log in to comment
patch (let me know if it works)