-
Notifications
You must be signed in to change notification settings - Fork 165
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
Using the Simple CRUD Example, Article Creation is not Persisted #151
Comments
After HOURS of debugging, I figured out the following:
Finally, after updating Below are the package versions I ended up using getting this to work properly. The commented text is the previous version found in your It should be noted that at the time of writing this, I was using
The full 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! |
Hello and thank you for your question. 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. |
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
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. |
Using the example found here:
https://github.com/amisadmin/fastapi-amis-admin/tree/master/fastapi_amis_admin/crud
Any attempt made to persist an "Article" in the SQLite DB fails. Also, starting a new project from scratch with this example fails over and over. Details below...
The example doesn't utilize the package that it claims to be an example for:
pip install fastapi-sqlmodel-crud
Installing fastapi-sqlmodel-crud causes the example to fail at this line:
from fastapi_amis_admin.crud import SQLModelCrud
Clearly, it appears that the fastapi_amis_admin package is what's required in this example. However, after installing it, the import line STILL doesn't work!
from fastapi_amis_admin.crud import SQLModelCrud
It isn't until I change that line to the following that things start lining up somewhat:
from fastapi_amis_admin.crud import SqlalchemyCrud
Then, changing this line makes python 3.11 happy again:
article_crud = SqlalchemyCrud(model=Article, engine=engine).register_crud()
However, when trying to run it, I'm forced to deal with this:
Which led me to this note:
https://github.com/amisadmin/fastapi-amis-admin/tree/master#note
And then led me to use this command:
pip install fastapi_amis_admin[sqlmodel]
Which allowed me to (FINALLY) run the example code, BUT got this lovely DeprecationWarning about "on_event" being deprecated.
Oh well, it's just a warning! I should be able to navigate to http://127.0.0.1:8000 right? WRONG. Can't do that yet because uvicorn (or comparable) wasn't used to actually start the app such that it be usable via browser! Ok no problem... I'm a grown man, I can add that in... so I installed uvicorn with pip and imported it and added the following line after the (deprecated!) startup function:
uvicorn.run(app, host="localhost", port=8000)
All should be well now, right? Starting it up and navigating to http://localhost:8000/docs does FINALLY start to look promising!
So I use the "Create Article" POST functionality on that page to create the following Article:
Clicking "Execute" does SEEM that the article was created, as it returns HTTP Status Code 200 and returns a new Article with ID 1. Additionally, when I use the "List Articles" POST function it also lists the article with ID 1 that I just created.
HOWEVER, when I open up amisadmin.db with an SQLite DB Client and look in the article table, no articles exist!
What am I doing wrong and why does the "Simple" example need so much work to get to this point?
I've attached my (modified) main.py as a txt file as well as my requirements.txt and SQLite DB in case this helps any:
main.py.txt
requirements.txt
amisadmin.db.zip
The text was updated successfully, but these errors were encountered: