mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-28 03:26:01 -04:00
- fix bug due to regression from #2793, make sure we only go to load
scalar attributes here and not relationships, else we get an error if there's no actual scalars to load
This commit is contained in:
@@ -728,8 +728,8 @@ def _finalize_insert_update_commands(base_mapper, uowtransaction,
|
||||
# it isn't expired.
|
||||
toload_now = []
|
||||
|
||||
if base_mapper.eager_defaults and state.unloaded:
|
||||
toload_now.extend(state.unloaded)
|
||||
if base_mapper.eager_defaults:
|
||||
toload_now.extend(state._unloaded_non_object)
|
||||
elif mapper.version_id_col is not None and \
|
||||
mapper.version_id_generator is False:
|
||||
prop = mapper._columntoproperty[mapper.version_id_col]
|
||||
|
||||
@@ -392,6 +392,15 @@ class InstanceState(interfaces._InspectionAttr):
|
||||
difference(self.committed_state).\
|
||||
difference(self.dict)
|
||||
|
||||
@property
|
||||
def _unloaded_non_object(self):
|
||||
return self.unloaded.difference(self._uses_objects)
|
||||
|
||||
@property
|
||||
def _uses_objects(self):
|
||||
return (attr for attr in self.manager
|
||||
if self.manager[attr].impl.uses_objects)
|
||||
|
||||
@property
|
||||
def expired_attributes(self):
|
||||
"""Return the set of keys which are 'expired' to be loaded by
|
||||
|
||||
@@ -854,9 +854,13 @@ class DefaultTest(fixtures.MappedTest):
|
||||
hohoval, default_t, Hoho = (self.other.hohoval,
|
||||
self.tables.default_t,
|
||||
self.classes.Hoho)
|
||||
Secondary = self.classes.Secondary
|
||||
|
||||
mapper(Hoho, default_t, eager_defaults=True)
|
||||
mapper(Hoho, default_t, eager_defaults=True, properties={
|
||||
"sec": relationship(Secondary)
|
||||
})
|
||||
|
||||
mapper(Secondary, self.tables.secondary_table)
|
||||
h1 = Hoho()
|
||||
|
||||
session = create_session()
|
||||
@@ -869,6 +873,14 @@ class DefaultTest(fixtures.MappedTest):
|
||||
|
||||
self.sql_count_(0, lambda: eq_(h1.hoho, hohoval))
|
||||
|
||||
# no actual eager defaults, make sure error isn't raised
|
||||
h2 = Hoho(hoho='fas', counter=5)
|
||||
session.add(h2)
|
||||
session.flush()
|
||||
eq_(h2.hoho, 'fas')
|
||||
eq_(h2.counter, 5)
|
||||
|
||||
|
||||
def test_insert_nopostfetch(self):
|
||||
default_t, Hoho = self.tables.default_t, self.classes.Hoho
|
||||
|
||||
|
||||
Reference in New Issue
Block a user