Comments (3)
Hello and thank you for your question.
Question 1. You can use sqlalchemy_database to add a fastapi main application middleware to achieve automatic submission.
app.add_middleware(site.db.asgi_middleware)
Issues 2 and 3. Dependent Version issues pyproject.toml contains dependent versions that are generally the latest available. I really didn't test the other versions.
The content in pdm.lock is not updated in a timely manner. Later, I will pay attention to this problem and try to synchronize the update.
from fastapi-amis-admin.
After HOURS of debugging, I figured out the following:
- You need to be using
session.commit()
instead ofsession.flush()
. This is also indicated in SQLModel's (and FastAPI's) documentation:
https://sqlmodel.tiangolo.com/tutorial/fastapi/simple-hero-api/#create-heroes-path-operation
https://fastapi.tiangolo.com/tutorial/sql-databases/#read-data - sqlite (specifically the
aiosqlite
package) required a newer version to be installed than the one specified in yourpdm.lock
file.aiosqlite==0.19.0
(wasaiosqlite==0.17.0
) - For my use case, I'm using MySQL (specifically
mysqlclient
), and it also requires a newer version to be installed than what I had.mysqlclient==2.2.1
Finally, after updating aiosqlite
, I figured out that the versions of the packages in your pdm.lock
file were out-of-date. After updating them, this example started working as expected! Woo!
Below are the package versions I ended up using getting this to work properly. The commented text is the previous version found in your pdm.lock
file. Also, if it's not too much trouble, it'd be fantastic if you included a requirements.txt
file in this repo.
It should be noted that at the time of writing this, I was using fastapi_amis_admin==0.7.0
of this package.
# aiosqlite==0.17.0
aiosqlite==0.19.0
# fastapi==0.92.0
fastapi==0.108.0
# pydantic==1.10.2
pydantic==2.5.3
# SQLAlchemy==1.4.41
SQLAlchemy==2.0.23
# sqlalchemy_database==0.1.0
sqlalchemy_database==0.1.1
# sqlmodel==0.0.8
sqlmodel==0.0.14
# typing_extensions==4.3.0
typing_extensions==4.9.0
The full requirements.txt
file I ended up with is below:
requirements.txt
Thanks for creating this ability to automatically generate the CRUD! It has been quite an adventure learning FastAPI, SQLModel, and now this in order to get this up and moving. Thank you!
from fastapi-amis-admin.
You can use sqlalchemy_database to add a fastapi main application middleware to achieve automatic submission.
app.add_middleware(site.db.asgi_middleware)
Shouldn't that be in the example then? Like I said, it doesn't work as-is. Regardless, thanks for letting me know about this! In the days I've been learning about this I've locally subclassed your SqlalchemyCrud
class with session.commit()
in place of session.flush()
and it's working as expected. Is there any particular reason you decided not to use session.commit()
?
Dependent Version issues pyproject.toml contains dependent versions that are generally the latest available. I really didn't test the other versions. The content in pdm.lock is not updated in a timely manner. Later, I will pay attention to this problem and try to synchronize the update.
Honestly, all I'm after is some way to use your (quite convenient!) codebase to implement all the CRUD for whatever I'm working on (and possibly other things too as I know this repo is intended for more than just this one use-case). If it means I need to look somewhere else for the prerequisite dependencies then I'd want to know where that is and how I can best install those.
from fastapi-amis-admin.
Related Issues (20)
- ➜ andy pip install fastapi_amis_admin[cli] zsh: no matches found: fastapi_amis_admin[cli] HOT 1
- 如何自定义某个search_fields字段的UI组件 HOT 3
- Setup id at runtime? HOT 6
- Passing primary_key is not supported when also passing a sa_column HOT 1
- can not create data from foreign key HOT 1
- 如何通过点击跳转到新页面? HOT 1
- 如何将ModelAdmin注册到PageAdmin中作为页面的一部分 HOT 1
- qq群还在吗,申请没人同意 HOT 2
- 启动报错AttributeError: secondary
- class BaseApiOut(GenericModel, Generic[_T], BaseApiSchema):TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
- 如何动态切换多语言
- S3 support
- Actions: custom PK (except id) is not passed to ModelAction.handle() HOT 6
- SqlAlchemy model with UUID column does not work properly
- KeyError: 'id'. self.pk: InstrumentedAttribute = self.model.__dict__[self.pk_name]
- The filter on input-group does not work
- "AttributeError: 'AdminSite' object has no attribute 'AnnotatedItemIdList'."
- JSONB, post raise exception
- 说下遇到的几个问题 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-amis-admin.