Closed
Description
Migrated issue, originally created by Sebastian Bank (@xflr6)
import sqlalchemy
import sqlalchemy.orm
engine = sqlalchemy.create_engine('sqlite://')
session = sqlalchemy.orm.Session(engine)
result = session.query(sqlalchemy.func.now())[0]
result.__dict__ # should raise AttributeError
print('\n'.join('%s\t%s' % (getattr(cls, '__slots__', None), cls)
for cls in result.__class__.mro()))
# () <class 'sqlalchemy.util._collections.result'>
# () <class 'sqlalchemy.util._collections._LW'>
# None <class 'sqlalchemy.util._collections.AbstractKeyedTuple'>
# None <type 'tuple'>
# None <type 'object'>
Note that __slots__
only works if every class along the mro spares instance __dict__
s.
__slots__ = ()
for sqlalchemy.util._collections.AbstractKeyedTuple
shoud fix this.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon May 14, 2015
Changes by Sebastian Bank (@xflr6):
sqlalchemy-bot commentedon May 14, 2015
Michael Bayer (@zzzeek) wrote:
.Query
returnsrows failed to implement
__slots__
correctly such that it stillhad a
__dict__
. This is resolved, but in the extremelyunlikely case someone was assigning values to the returned tuples,
that will no longer work.
fixes LW KeyedTuples have instance dicts (ineffective __slots__) #3420
→ 64c1f2e
sqlalchemy-bot commentedon May 14, 2015
Changes by Michael Bayer (@zzzeek):
sqlalchemy-bot commentedon May 14, 2015
Michael Bayer (@zzzeek) wrote:
thanks for catching that. countdown to someone was assigning to the tuple in 5..4..
sqlalchemy-bot commentedon May 15, 2015
Michael Bayer (@zzzeek) wrote:
.. 3... 2.. 1.. GO !!! https://groups.google.com/forum/#!topic/sqlalchemy/syWt_EZqCbk
this user is already getting an error even without the change here because they want to set one of the actual named attributes.
sqlalchemy-bot commentedon May 15, 2015
Sebastian Bank (@xflr6) wrote:
Uh, you really know your users damn well!
I think Python even raises with new attributes (with and without the change).
I was curious if the change affects the benchmarks from the docs (maybe for some that would count as argument for/against
__slots__
).sqlalchemy-bot commentedon May 15, 2015
Michael Bayer (@zzzeek) wrote:
__slots__
doesn't have a huge impact on speed, it is very useful for keeping memory under control though. The amount of memory that was being wasted throughout huge parts of SQLA on dictionaries that were hardly needed is why I put a lot of__slots__
in 1.0.sqlalchemy-bot commentedon Sep 18, 2015
Rodrigo Menezes (@rclmenezes) wrote:
Awww mannnn. You caught me :)
I assigned some helper lambdas to the returning rows:
Any chance we'll get row_cls as an option to sessionmaker? I found these helper lambdas super useful in certain scenarios.
sqlalchemy-bot commentedon Sep 18, 2015
Michael Bayer (@zzzeek) wrote:
you can use Column Bundles and assign any kind of ORM-level processing to column-loads that you'd want.
sqlalchemy-bot commentedon Sep 18, 2015
Michael Bayer (@zzzeek) wrote:
for interception of objects as they are loaded you can use the load event.
sqlalchemy-bot commentedon Sep 18, 2015
Rodrigo Menezes (@rclmenezes) wrote:
Whoa! Column bundles are great. Thanks!