Skip to content

Fixed the rendering of the metadata argument with SQLModel#466

Merged
agronholm merged 1 commit intomasterfrom
fix-465
Feb 24, 2026
Merged

Fixed the rendering of the metadata argument with SQLModel#466
agronholm merged 1 commit intomasterfrom
fix-465

Conversation

@agronholm
Copy link
Owner

Changes

This fixes the missing metadata argument when rendering a plain Table with the SQLModel generator.
It contains a hack that replaces self.base.metadata_ref which is otherwise overridden by the declarative generator during generate_models().

Fixes #465.

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.

@coveralls
Copy link

Coverage Status

coverage: 97.785% (+0.1%) from 97.668%
when pulling 84e3aa7 on fix-465
into 94878f9 on master.

@sheinbergon
Copy link
Collaborator

Changes

This fixes the missing metadata argument when rendering a plain Table with the SQLModel generator. It contains a hack that replaces self.base.metadata_ref which is otherwise overridden by the declarative generator during generate_models().

You can probably juat extract the metadata_ref in the base class instead of overriding and calling the super, which would also make things less hacky.

@agronholm
Copy link
Owner Author

Changes

This fixes the missing metadata argument when rendering a plain Table with the SQLModel generator. It contains a hack that replaces self.base.metadata_ref which is otherwise overridden by the declarative generator during generate_models().

You can probably juat extract the metadata_ref in the base class instead of overriding and calling the super, which would also make things less hacky.

I have no idea what this would mean in practice.

@agronholm
Copy link
Owner Author

The core problem is that DeclarativeModelGenerator.generate_models() steamrolls self.base if it detects that there are no model classes.

@agronholm
Copy link
Owner Author

I came up with a more elegant solution but it turned out to require an API change so I scrapped it.

@agronholm agronholm merged commit 4dd547e into master Feb 24, 2026
8 checks passed
@agronholm agronholm deleted the fix-465 branch February 24, 2026 22:12
@sheinbergon sheinbergon added this to the 4.0.2 milestone Feb 24, 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.

sqlmodel: dangling comma for fallback tables

3 participants