question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`sqlalchemy.Column` parameters are not passed forward when set on `sqlmodel.Field` and a column is provided via `sa_column`

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • 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".

Operating System

Linux

Operating System Details

No response

SQLModel Version

0.0.6

Python Version

3.9.5

Additional Context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
oldfielj-anstocommented, 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.

0reactions
github-actions[bot]commented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapping Table Columns - SQLAlchemy 1.4 Documentation
Mapping Table Columns¶. Introductory background on mapping to columns falls under the subject of Table configuration; the general form falls ...
Read more >
FastAPI with Async SQLAlchemy, SQLModel, and Alembic
This tutorial looks at how to configure SQLAlchemy, SQLModel, and Alembic to work with FastAPI asynchronously.
Read more >
python - How to make a double foreign key as a primary key in ...
When I have a look at the tables (see below), I see the cascading delete for group via foreign key user_id . However,...
Read more >
SQLModel: SQL DBs based on Python type hints. The ... - Reddit
And you can also use inheritance to avoid duplication of fields/columns, but customize, include, exclude fields in the data models for input and ......
Read more >
marshmallow-sqlalchemy - Read the Docs
0: Add partial parameter. class marshmallow_sqlalchemy.fields.Related(columns=None, column=None, **kwargs). Related data represented by a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found