Skip to content

Conversation

@kyo-ago
Copy link
Member

@kyo-ago kyo-ago commented Nov 27, 2025

Summary

  • Fixed SAWarning that occurred when using sqlacodegen with SQLAlchemy 2.0
  • Changed metadata.reflect() call to use explicit keyword arguments instead of positional arguments

Problem

When running sqlacodegen with SQLAlchemy 2.0, the following warning was displayed:

SAWarning: Can't validate argument 'dialect_options'; can't locate any SQLAlchemy dialect named 'dialect'

This occurred because positional arguments were being passed to MetaData.reflect(), which in SQLAlchemy 2.0 expects keyword arguments after the first positional argument (bind).

Changes

Changed line 59 in src/sqlacodegen/cli.py:

Before:

metadata.reflect(engine, schema, not args.noviews, tables)

After:

metadata.reflect(bind=engine, schema=schema, views=not args.noviews, only=tables)

Impact

  • ✅ No functional changes - behavior is identical
  • ✅ Backward compatible with SQLAlchemy 1.x and 2.x
  • ✅ Generated model code remains exactly the same
  • ✅ Eliminates SQLAlchemy 2.0 warning

Test plan

  • Run sqlacodegen with the fix and verify the warning no longer appears
  • Verify the generated models are identical to before the fix
  • Test with various database schemas

🤖 Generated with Claude Code

… warning

Fixed SAWarning that occurred due to positional arguments being
misinterpreted as dialect_options in SQLAlchemy 2.0.

Changes:
- Changed metadata.reflect() call to use explicit keyword arguments
- bind=engine instead of positional argument
- schema=schema instead of positional argument
- views=not args.noviews instead of positional argument
- only=tables instead of positional argument

This resolves the warning:
"Can't validate argument 'dialect_options'; can't locate any
SQLAlchemy dialect named 'dialect'"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kyo-ago kyo-ago closed this Nov 27, 2025
@kyo-ago kyo-ago deleted the fix-metadata-reflect-args-latest branch November 27, 2025 05:22
@kyo-ago kyo-ago restored the fix-metadata-reflect-args-latest branch November 27, 2025 05:22
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