Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Allow type_ kwarg in sa_column_kwargs #158

Closed

Conversation

RobertRosca
Copy link
Contributor

@RobertRosca RobertRosca commented Nov 17, 2021

In #156 @phi-friday wanted to pass sa_column_kwargs={"type_": Unicode} to a Field to set the column to nvarchar, doing this causes an exception:

File "/usr/local/lib/python3.9/site-packages/sqlalchemy/sql/schema.py", line 1586, in __init__
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: May not pass type_ positionally and as a keyword.

sa_type is passed by get_column_from_field as a positional argument, so passing it through at a kwarg leads to this exception.

PR checks if type_ is in the kwargs, and if it is it pops it from the kwargs and sets sa_type to its value.

Also added a test for this case, @tiangolo is issue-related tests in a separate directory a thing you like? It's not done in FastAPI or here, so if not I'll move it.


Edit: whoops, forgot the sa_column argument existed, given that this seems kind of pointless 🤔

@tiangolo
Copy link
Member

Thanks @RobertRosca! SQLAlchemy only allows types in the sequential arguments, not in keyword arguments. So it would have been in sa_column_args. But still, probably more control in sa_column.

Either way, there's now support for sa_type which should simplify it: #505

That will be available in 0.0.11. 🎉

Given that, I'll close this one, thanks for the effort! ☕

@tiangolo tiangolo closed this Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants