fastapi-amis-admin
fastapi-amis-admin copied to clipboard
Using the Simple CRUD Example, Article Creation is not Persisted
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:
from pydantic_settings import BaseSettings # noqa: F401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pydantic_settings'
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:
[
{
"title": "This is an article",
"description": "Such description!",
"status": true,
"content": "Much wow"
}
]
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