Skip to content

Commit

Permalink
Add stronger assertion that the related object is the same
Browse files Browse the repository at this point in the history
  • Loading branch information
mskrip committed Aug 8, 2024
1 parent dfd9b30 commit b42b7bb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ class Hero(SQLModel, table=True):

with Session(engine) as session:
hero = session.get(Hero, 1)
assert not session.dirty
assert not session.new
assert session._is_clean()

Hero.validate(hero)
new_hero = Hero.validate(hero)

assert not session.dirty
assert not session.new
assert session._is_clean()
# The new hero is a different instance, but the team is the same
assert id(new_hero) != id(hero)
assert id(new_hero.team) == id(hero.team)


@needs_pydanticv2
Expand Down Expand Up @@ -127,6 +128,9 @@ class Hero(SQLModel, table=True):
hero = session.get(Hero, 1)
assert session._is_clean()

Hero.model_validate(hero)
new_hero = Hero.model_validate(hero)

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

0 comments on commit b42b7bb

Please sign in to comment.