You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sqlalchemy.Column parameters are not passed forward when set on sqlmodel.Field and a column is provided via sa_column #314
I used the GitHub search to find a similar issue and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
name: str=Field(
sa_column=Column(
String,
# ... other attrs not exposed in sqlmodel.Field today
),
index=True# this is ignored, must be set on `Column` above
)
Description
sqlmodel.Field exposes some but not all fields from sqlalchemy.Column. This means in some cases it is necessary to provide a Column via the sa_column= param on sqlmodel.Field. However, when this is the case the parameters set on sqlmodel.Field are not forwarded to the new sa_column object.
I think the expected behavior here is that parameters set on Field would be combined with those from the sa_column object. Either this or setting a parameter that will be ignored should trigger a warning/exception along the lines of "You have set index but also provided a sqlalchemy.Column object, index will be ignored".
@JLHasson I agree that this functionality doesn't really work as expected. I've seen a few other issues where people have run into similar issues, but I'm not sure there is a perfect solution to fix the problem.
Maybe like you suggest a warning should be added, the docs could definitely use some improvement, as I don't think the "sa_column" parameter is even documented at the moment.
For more complex projects I'd probably suggest people stick with vanilla SQLAlchemy.
I spent quite some time, figuring out why indexes were not being set.
Can we add this in the documentation atleast? It will be helpful for people who need to use custom datatypes like BIGINT and also need a index for that column
Activity
oldfielj-ansto commentedon Apr 26, 2022
@JLHasson I agree that this functionality doesn't really work as expected. I've seen a few other issues where people have run into similar issues, but I'm not sure there is a perfect solution to fix the problem.
Maybe like you suggest a warning should be added, the docs could definitely use some improvement, as I don't think the "sa_column" parameter is even documented at the moment.
For more complex projects I'd probably suggest people stick with vanilla SQLAlchemy.
adpmhel24 commentedon May 2, 2022
same issue, i hope they will fix it :(
jinll2021 commentedon Jun 23, 2022
same issue, i hope they will fix it , hope sa_column will be more descriptions in the documentation,thanks
ronalddas commentedon Oct 11, 2022
I spent quite some time, figuring out why indexes were not being set.
Can we add this in the documentation atleast? It will be helpful for people who need to use custom datatypes like BIGINT and also need a index for that column
tiangolo commentedon Nov 11, 2022
Yep, when you pass a Column you are overriding all the SQLAlchemy part, and those fields end up only used by Pydantic.
I still have to document that, but that's the intention.
github-actions commentedon Nov 22, 2022
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.