Skip to content

Commit 29ee43d

Browse files
committed
Add stronger assertion that the related object is the same
1 parent ad51506 commit 29ee43d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tests/test_validation.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ class Hero(SQLModel, table=True):
9191

9292
with Session(engine) as session:
9393
hero = session.get(Hero, 1)
94-
assert not session.dirty
95-
assert not session.new
94+
assert session._is_clean()
9695

97-
Hero.validate(hero)
96+
new_hero = Hero.validate(hero)
9897

99-
assert not session.dirty
100-
assert not session.new
98+
assert session._is_clean()
99+
# The new hero is a different instance, but the team is the same
100+
assert id(new_hero) != id(hero)
101+
assert id(new_hero.team) == id(hero.team)
101102

102103

103104
@needs_pydanticv2
@@ -127,6 +128,9 @@ class Hero(SQLModel, table=True):
127128
hero = session.get(Hero, 1)
128129
assert session._is_clean()
129130

130-
Hero.model_validate(hero)
131+
new_hero = Hero.model_validate(hero)
131132

132133
assert session._is_clean()
134+
# The new hero is a different instance, but the team is the same
135+
assert id(new_hero) != id(hero)
136+
assert id(new_hero.team) == id(hero.team)

0 commit comments

Comments
 (0)