Skip to content

Conversation

@agronholm
Copy link
Owner

Changes

Fixes #376.

Refactors the API in such a way that lets the SQLModel code generator pass relationship arguments to the underlying SQLAlchemy relationship.

Checklist

If this is a user-facing code change, like a bugfix or a new feature, please ensure that
you've fulfilled the following conditions (where applicable):

  • You've added tests (in tests/) which would fail without your patch
  • You've added a new changelog entry (in CHANGES.rst).

If this is a trivial change, like a typo fix or a code reformatting, then you can ignore
these instructions.

Updating the changelog

If there are no entries after the last release, use **UNRELEASED** as the version.
If, say, your patch fixes issue #123, the entry should look like this:

- Fix big bad boo-boo in task groups
  (`#123 <https://github.com/agronholm/sqlacodegen/issues/123>`_; PR by @yourgithubaccount)

If there's no issue linked, just link to your pull request instead by updating the
changelog after you've created the PR.

Fixes #376.

# Conflicts:
#	CHANGES.rst

# Conflicts:
#	CHANGES.rst

# Conflicts:
#	CHANGES.rst
@agronholm agronholm requested a review from sheinbergon February 8, 2026 17:36
@coveralls
Copy link

coveralls commented Feb 8, 2026

Coverage Status

coverage: 97.685% (+0.1%) from 97.572%
when pulling d32e4be on fix-sqlmodel-onetomany-multiref
into 4772a34 on master.

Copy link
Collaborator

@sheinbergon sheinbergon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added 2 comments that are mostly cosmetic. Juding by the test, looks like it does what it's supposed to do. Very nice code cleanup

Approved. Do with the comments as you see fit

@sheinbergon sheinbergon modified the milestones: 4.0.0rc3, 4.0.x Feb 9, 2026
Copy link
Collaborator

@sheinbergon sheinbergon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just put the new changes in their own dedicated block

@sheinbergon sheinbergon self-requested a review February 9, 2026 20:11
Copy link
Collaborator

@sheinbergon sheinbergon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved again. Resolve the comments as you see fit

@agronholm agronholm merged commit de3f846 into master Feb 9, 2026
8 checks passed
@agronholm agronholm deleted the fix-sqlmodel-onetomany-multiref branch February 9, 2026 21:12
@agronholm
Copy link
Owner Author

I could do another PR for that migration away from Optional.

@sheinbergon
Copy link
Collaborator

I could do another PR for that migration away from Optional.

Sounds great.

@agronholm
Copy link
Owner Author

I hit a wrinkle: KeyError: 'SimpleContainers | None' <- this works with 'Optional[SimpleContainers]'. I could try to add from __future__ import annotations but I don't know yet how that will mesh with SQLModel (Pydantic historically reacted badly to deferred annotations).

@agronholm
Copy link
Owner Author

I guess they must've made it work since Python 3.14 has that on by default.

@agronholm
Copy link
Owner Author

Yeah, this is a no go: sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[OtherItems(other_items)], expression 'SimpleOnetoone | None' failed to locate a name ('SimpleOnetoone | None'). If this is a class name, consider adding this relationship() to the <class 'OtherItems'> class after both dependent classes have been defined.

@agronholm
Copy link
Owner Author

One would think this stupid issue had been fixed by now but I guess not.

@sheinbergon
Copy link
Collaborator

Yeah, this is a no go: sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper[OtherItems(other_items)], expression 'SimpleOnetoone | None' failed to locate a name ('SimpleOnetoone | None'). If this is a class name, consider adding this relationship() to the <class 'OtherItems'> class after both dependent classes have been defined.

Well, you gave it a try

@agronholm
Copy link
Owner Author

Did you want to get something else into the final release?

@sheinbergon
Copy link
Collaborator

Did you want to get something else into the final release?

I wanted to run a manual test on the enum arrays before proceeding to 4.0.0 GA. I'll get to it today / tomorrow, and we can proceed to the final release

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.

SQLModel Generator does not include foreign_keys in relationships

3 participants