Uh oh!
There was an error while loading. Please reload this page.
migration to sqlalchemy 2.0 - #563
Conversation
📝 Docs preview for commit 60318b4 at: https://6406825e11187c06ceaecaf0--sqlmodel.netlify.app |
mortendaehli
commented
Mar 24, 2023
@farahats9, great! Do you think you would be able to sort out the failing tests? :) |
farahats9
commented
Mar 24, 2023
I fixed some of the |
📝 Docs preview for commit b48423f at: https://641d9f2736a7fa1c9568bdb7--sqlmodel.netlify.app |
Uh oh!
There was an error while loading. Please reload this page.
honglei
commented
Mar 31, 2023
I used this version in my project with env: |
Co-authored-by: Stefan Borer <stefan.borer@gmail.com>
📝 Docs preview for commit 9c219d9 at: https://6426bd112dc67b078b6e5298--sqlmodel.netlify.app |
📝 Docs preview for commit 0eee8e8 at: https://6426be4468302c086218a5bb--sqlmodel.netlify.app |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
📝 Docs preview for commit 050cf02 at: https://6426c1ce9df2a80bfd37ae93--sqlmodel.netlify.app |
gabrielmbmb
commented
Apr 12, 2023
@farahats9 someone created a PR on your fork for fixing the mypy issues |
heyaco
commented
Apr 20, 2023
This seems good to go just needs merging |
8thgencore
commented
Apr 20, 2023
We are very much waiting for this change |
antont
commented
Apr 21, 2023
Why do you wait, instead of taking it to use? I guess feedback from users would be helpful info also for the maintainer to know when to merge. |
me-v2
commented
Apr 24, 2023
🚀 👀👀 |
synodriver
commented
Apr 24, 2023
Great! I would love to try this branch in my production environment. |
k-s-t-i
commented
Apr 24, 2023
Would like to see this merged for asyncpg support. Asyncpg seems to greatly increase performance based on most simple benchmarks. |
@k-s-t-i You can currently use Asyncpg with sqlalchemy v1.4 and sqlmodel v0.0.8 with no issue in most cases. you will need to watch out for some problems like lazy loading and cascading deletes on the orm side. |
synodriver
commented
Apr 25, 2023
Update: This patch can work with asyncmy in a real project. Will try asyncpg later. |
Uh oh!
There was an error while loading. Please reload this page.
synodriver
commented
Apr 26, 2023
Update: asyncpg works too. Tested with a real project on both windows and linux. Notice: to make relationship work, you may use |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
honglei
commented
Jun 27, 2023
Five months have been passed since the release of SQLalchemy2.0, https://www.sqlalchemy.org/blog/2023/01/26/sqlalchemy-2.0.0-released/ |
antont
commented
Jun 27, 2023
You can help by using this PR in your project(s) if you want, and reporting how well it works. |
50Bytes-dev
commented
Jul 10, 2023
Been working with this PR for almost a month now, works great. Thank you! |
Sorry but changing the order of classes definition does not solve the error for me. At this point, I don't know what to do, but this branch is useless for me. I already have done what you mentioned, but the error persists. It always says My project has about 30 tables at this point, and it has been running for quite 1 year. My project does not run The error messages are not helpful at all. And they only happen in this specific PR. I understand it may be working for a very simple case like you presented, but for me it is always showing these errors, no matter how much code I change: py", line2479, inget_propertyreturnself._props[key]
KeyError: 'user'or annotation=eval(expression, base_globals, locals_)
File"<string>", line1, in<module>NameError: name'PostUserLike'isnotdefinedor .py", line223, ineval_expressionraiseNameError(
NameError: Couldnotde-stringifyannotation'PostUserLike'or ", line2342, in_extract_mapped_subtypeifraiseerrand"Mapped["inraw_annotation: # type: ignoreTypeError: argumentof type 'ForwardRef'isnotiterableMy current API is running perfectly with If someone wants to investigate the issue with me, I am willing to screenshare and show the project structure and try to make it to work; my Discord is But one thing I wonder, even if I were able to make this PR to work on my code base after countless changes, I don't think this is how library updates are supposed to work? Every time I type This PR is certainly introducing breaking changes but I'm unable to tell what and why exactly, although I investigated a lot here I couldn't even make my project to run with it. By the way I woud love to be using |
farahats9
commented
Jul 10, 2023
@FilipeMarch you are right there is an issue in I feel this is a priority to fix over the mypy linting, I will do my best to figure it out but any help is appreciated. |
I had an error # models/__init__.py# need for alembicfrom . import (
company,
location,
client
)# models/company.pyifTYPE_CHECKING:
frommodels.locationimportLocationfrommodels.clientimportClientclassCompany(BaseModel, CompanyBase, table=True):
locations: List["Location"] =Relationship(back_populates="company")
clients: List["Client"] =Relationship(back_populates="company")# models/location.pyfrommodels.companyimportCompanyclassLocation(BaseModel, OrderedList, LocationBase, table=True):
company_id: int=Field(default=None, foreign_key="company.id")
company: Company=Relationship(back_populates="locations")# models/client.pyfrommodels.companyimportCompanyclassClient(ClientBase, BaseModel, table=True):
company_id: int=Field(default=None, nullable=False, foreign_key="company.id")
company: Company=Relationship(back_populates="clients") |
matanper
commented
Jul 20, 2023
Hey @farahats9, I'm getting error when using sqlalchemy relationship: classHero(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
powers: List["Power"] =Relationship(
sa_relationship=relationship(back_populates='hero')
)
classPower(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
hero_id: int=Field(foreign_key="hero.id")
hero: "Hero"=Relationship(back_populates="powers")any idea why? |
@matanper I think the forward Relationship (with the Foreign Key) needs to be a proper class, and not a type string. Can you try this? classHero(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
powers: List["Power"] =Relationship(
sa_relationship=relationship(back_populates='hero')
)
classPower(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
hero_id: int=Field(foreign_key="hero.id")
hero: Hero=Relationship(back_populates="powers") # <== No quotes around Hero |
peterlandry
commented
Jul 27, 2023
I've looked at this PR a bit to try cleaning up the linting errors. I've reduced most of them, but q=User.name=="spongebob"
This shows up as an error, but is correct at runtime. At runtime, we see an |
Fix most linting errors
honglei
commented
Jul 28, 2023
Environment: pytest errors: |
tiangolo
commented
Nov 18, 2023
TL;DR: Good news, this is available in the just released SQLModel 0.0.12! 🎉 Awesome, thanks a lot for all the work @farahats9! 🚀 And thanks everyone for the comments, reviews, etc. ☕ @farahats9 I continued the work here with several things on top on PR #700. I took your commits so you're co-author of that PR (and contributor to SQLModel, check your badge here next to your username, or in https://github.com/tiangolo/sqlmodel/graphs/contributors 😎 ). I did a few extra things:
It is now available in SQLModel 0.0.12. 🎉 As this is now included in the repo and released, I'll now close this PR. Thanks! 🍰 |
Hope it can help : I had the same issue because the relationsship was always defined and I didn' decalre it Optional : |
made the required changes to pass the tests for sqlalchemy 2.0
python version had to be pumped to 3.7 instead of 3.6
removed sqlalchemy2-stubs since it is not compatible or required.
More testing in a real project scenario is welcome.