MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_lazyattr_commit

Method test_lazyattr_commit

test/orm/test_unitofwork.py:1940–1979  ·  view source on GitHub ↗

Lazily loaded relationships. When a lazy-loaded list is unloaded, and a commit occurs, that the 'passive' call on that list does not blow away its value

(self)

Source from the content-addressed store, hash-verified

1938 eq_(u.syn_name, "User:some name:User")
1939
1940 def test_lazyattr_commit(self):
1941 """Lazily loaded relationships.
1942
1943 When a lazy-loaded list is unloaded, and a commit occurs, that the
1944 'passive' call on that list does not blow away its value
1945
1946 """
1947
1948 users, Address, addresses, User = (
1949 self.tables.users,
1950 self.classes.Address,
1951 self.tables.addresses,
1952 self.classes.User,
1953 )
1954
1955 self.mapper_registry.map_imperatively(
1956 User,
1957 users,
1958 properties={
1959 "addresses": relationship(
1960 self.mapper_registry.map_imperatively(Address, addresses)
1961 )
1962 },
1963 )
1964
1965 u = User(name="u1")
1966 u.addresses.append(Address(email_address="u1@e1"))
1967 u.addresses.append(Address(email_address="u1@e2"))
1968 u.addresses.append(Address(email_address="u1@e3"))
1969 u.addresses.append(Address(email_address="u1@e4"))
1970
1971 session = fixture_session()
1972 session.add(u)
1973 session.flush()
1974 session.expunge_all()
1975
1976 u = session.query(User).one()
1977 u.name = "newname"
1978 session.flush()
1979 eq_(len(u.addresses), 4)
1980
1981 def test_inherits(self):
1982 """a user object that also has the users mailing address."""

Callers

nothing calls this directly

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
eq_Function · 0.90
map_imperativelyMethod · 0.80
UserClass · 0.70
AddressClass · 0.70
appendMethod · 0.45
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
oneMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected