Skip to content

test: assert sqlmodel_update fluent identity and Session.exec non-scalar queries - #2126

Closed
janmejai2002 wants to merge 1 commit into
fastapi:mainfrom
janmejai2002:test/sqlmodel-update-and-exec-invariants
Closed

janmejai2002 wants to merge 1 commit into
fastapi:mainfrom
janmejai2002:test/sqlmodel-update-and-exec-invariants

Conversation

@janmejai2002

Copy link
Copy Markdown

Description

This PR improves unit test coverage and assertions for two core SQLModel APIs:

  1. sqlmodel_update() method contracts:

    • tests/test_update.py previously invoked org.sqlmodel_update(...) without asserting the updated field values or verifying that the method returns self.
    • Adds concrete assertions verifying that sqlmodel_update() updates model attributes, preserves unmodified fields, and adheres to the fluent return contract (assert result is org).
    • Adds test coverage for dictionary updates (sqlmodel_update({"name": ...})), ensuring non-model keys in dictionaries or updates are safely ignored without polluting attributes.
    • Adds validation coverage asserting that ValueError is raised when unsupported types (non-dict, non-BaseModel) are passed to sqlmodel_update().
  2. Session.exec() non-scalar queries and bulk updates:

    • Session.exec() distinguishes between SelectOfScalar (which unwraps scalars) and standard Select / UpdateBase queries (which return tuples or CursorResult).
    • Unit tests in tests/test_query.py previously only covered single-model scalar selects (select(Hero)).
    • Adds unit test cases verifying:
      • session.exec(select(Hero.id, Hero.name)) properly returns row tuples ((hero.id, "Deadpond")).
      • session.exec(update(Hero)...) returns a valid CursorResult with expected .rowcount == 1.

Verification

  • Tests: Ran pytest tests/test_update.py tests/test_query.py -v: 7 passed in 0.12s.
  • Linter: Ran ruff check and ruff format --check: all checks passed, 0 errors.
  • Dependencies & Mocks: Zero synthetic mocks. Uses standard SQLite engine and native SQLModel / SQLAlchemy types.

@YuriiMotov

YuriiMotov commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

@janmejai2002, please stop ignoring contribution guidelines and PR template (I already warned you here).
If you keep ignoring rules, we will have to ban you

@YuriiMotov YuriiMotov closed this Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants