Skip to content

Commit

Permalink
fix: Correct the AutogenContext.metadata typing to include Sequence[M…
Browse files Browse the repository at this point in the history
…etaData].

### Description
The type annotation for AutogenContext.metadata is currently `Optional[MetaData]`, but `target_metadata` is `Union[MetaData, Sequence[MetaData], None]`. Seems like setting `target_metadata` to `[]` directly translates into the list that `AutogenContext` receives, and that the code is already coercing the potential single/sequence to always be a list.

My alembic plugin wasn't aware that this **could** be a list, and as such wasn't handling the possibility properly.

### Checklist
<!-- go over following points. check them with an `x` if they do apply, (they turn into clickable checkboxes once the PR is submitted, so no need to do everything at once)

-->

This pull request is:

- [x] A documentation / typographical error fix
	- Good to go, no issue or tests are needed
- [ ] A short code fix
	- please include the issue number, and create an issue if none exists, which
	  must include a complete example of the issue.  one line code fixes without an
	  issue and demonstration will not be accepted.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.   one line code fixes without tests will not be accepted.
- [ ] A new feature implementation
	- please include the issue number, and create an issue if none exists, which must
	  include a complete example of how the feature would look.
	- Please include: `Fixes: #<issue number>` in the commit message
	- please include tests.

**Have a nice day!**

Closes: #1547
Pull-request: #1547
Pull-request-sha: 1bdfa18

Change-Id: Ib3114b19c10983114b834676ada69d7475e82fe5
  • Loading branch information
DanCardin authored and sqla-tester committed Nov 6, 2024
1 parent b6b44c1 commit 191c14a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions alembic/autogenerate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class AutogenContext:
"""Maintains configuration and state that's specific to an
autogenerate operation."""

metadata: Optional[MetaData] = None
metadata: Union[MetaData, Sequence[MetaData], None] = None
"""The :class:`~sqlalchemy.schema.MetaData` object
representing the destination.
Expand Down Expand Up @@ -332,7 +332,7 @@ class AutogenContext:
def __init__(
self,
migration_context: MigrationContext,
metadata: Optional[MetaData] = None,
metadata: Union[MetaData, Sequence[MetaData], None] = None,
opts: Optional[Dict[str, Any]] = None,
autogenerate: bool = True,
) -> None:
Expand Down

0 comments on commit 191c14a

Please sign in to comment.