Giter Club home page Giter Club logo

Comments (3)

amisadmin avatar amisadmin commented on June 3, 2024 1

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.

starryknight64 avatar starryknight64 commented on June 3, 2024

After HOURS of debugging, I figured out the following:

  1. You need to be using session.commit() instead of session.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
  2. sqlite (specifically the aiosqlite package) required a newer version to be installed than the one specified in your pdm.lock file. aiosqlite==0.19.0 (was aiosqlite==0.17.0)
  3. 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.

starryknight64 avatar starryknight64 commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.