-
-
Notifications
You must be signed in to change notification settings - Fork 701
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
SQLAlchemy-Continuum compatibility #346
Comments
For what it's worth, I am seeing this error even without sqlmodel or sqlalchemy_continuum. Did you ever find the root cause? |
@petyunchik were you able to get this working? upgrading pydantic fixes that issue, however, there are a couple other issues that then you have to work through, both with continuum and sqlmodel |
As of today (i.e. sqlmodel 0.0.14 and sqlalchemy-continuum 1.4.0), the error is
Couldn't debug it properly, but I assume this is due to the fact that continuum create sqlalchemy models for versioning, but do not annotate these models. I think I'll have to deal with this problem, because versioning is of the essence for some of my applications. My intuition tells that it is best to create a new module by patching sqlalchemy-continuum to use sqlmodel's Base and registry, rather than adapting any of these to use the other |
@ftapajos thank you for the suggestion. Any update on this? I am interested in contributing 🙏 |
Related: kvesteri/sqlalchemy-continuum#271 @tiangolo any thoughts on this would be greatly appreciated! 🙏 |
@abrichr I haven't even started yet, but I could follow your lead |
Really hoping a solution is in the works here. |
Can't wait to be compatible. I really need this feature. |
I found a solution. I'm currently using:
Before declaring any model, do the following:
This should work with SQLModels. Your models should inherit from BaseSQLModel. If you use SQL Server as your database, you may encounter an error due to a sequence definition in the id column of the TransactionClass. You can rewrite the TransactionClass as shown below to address this issue. Additionally, I use a FastAPIPlugin to retrieve the user from the session. All you need to do is set the user data in the session.info dictionary. Here is the complete code I use:
|
First Check
Commit to Help
Example Code
Description
Very basic setup of SQLAlchemy-Continuum doesn't work with SQLModel. Following error raised (see here):
SQLModel
class misses some expected attribute (registry
for SQLAlchemy >= 1.4) from SQLAlchemy'sBase
. For debugging purposes the attribute can be manually populated (uncomment# setattr(SQLModel, 'registry', default_registry)
in the example code) and it helps to proceed to the next error:Looks like there is some incompatibility with SQLAlchemy's expected behaviour, because this error was thrown just after SQLModel's
__new__
method call.Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.10.2
Additional Context
No response
The text was updated successfully, but these errors were encountered: