Giter Site home page Giter Site logo

Comments (9)

LuisLuii avatar LuisLuii commented on May 25, 2024

Hi could you share some infomation to let me reproduce your issue? such as the SQLalchemy schema, and the code

from fastapiquickcrud.

AntonyM71 avatar AntonyM71 commented on May 25, 2024

Hi Luis, I've been using the User Model from the first demo.

class User(Base):
    __tablename__ = 'test_users'
    id = Column(Integer, primary_key=True, autoincrement=True, unique=True)
    name = Column(String, nullable=False)
    email = Column(String, nullable=False)

crud_route_1 = crud_router_builder(db_model=User,
                                   prefix="/user",
                                   tags=["User"],
                                    db_session=session,
                                    sql_type=SqlType("postgresql"),
                                #    async_mode=True
                                   )


app = FastAPI()
app.include_router(crud_route_1)

Initially I thought it was due to an environment clash, as I was using Conda with pip dependencies, however the issue seems to persist when the versions are pinned to those in the Readme, and even with only fastapi-quickcrud in the environment.

I've tried recreating your "Simple Code" example in another file, and even with only fastapi-quickcrud in the environment the issue seems to be there. The only changes I made were to point at a postrgess database, with

    db_session=session,
    sql_type=SqlType("postgresql"),

from fastapiquickcrud.

LuisLuii avatar LuisLuii commented on May 25, 2024

many thanks Antony, I still no idea about the local_kw , btw could you run that normally without set the session like the following example, which is using in-memory db
https://github.com/LuisLuii/FastAPIQuickCRUD/blob/main/tutorial/sample.py
or could you share your full code that includes the session part of code.

from fastapiquickcrud.

AntonyM71 avatar AntonyM71 commented on May 25, 2024

Hi Luis,

Running the example at https://github.com/LuisLuii/FastAPIQuickCRUD/blob/main/tutorial/sample.py works fine, so I'll use that for now :)

from fastapiquickcrud.

AntonyM71 avatar AntonyM71 commented on May 25, 2024

Looking back to postures integration, it seems that the local_kw appears when we add the following lines to our model

     db_session=async_session,
     sql_type=SqlType("postgresql"),

e.g. from:

crud_route_child = generic_sql_crud_router_builder(
    db_model=Child,
    prefix="/child",
    tags=["child"],
)

to :

crud_route_child = generic_sql_crud_router_builder(
    db_model=Child,
    prefix="/child",
    tags=["child"],
    db_session=async_session,
    sql_type=SqlType("postgresql"),
)

for reference, the async session is:

engine = create_engine("postgresql://xxxx:[email protected]/xxxxx")
session = sessionmaker(engine)

async_session = sessionmaker(
    autocommit=False,
    autoflush=False,
    bind=engine,
)

from fastapiquickcrud.

LuisLuii avatar LuisLuii commented on May 25, 2024

Thanks Antony! I have reproduced it based on your information. And It is due to my documentation is not clear enough.

I saw you has used the async_session to be db_session argument. The correct way is like the following

engine = create_engine("postgresql://xxxx:[email protected]/xxxxx")
session = sessionmaker(engine)

def get_transaction_session():
    try:
        db = session()
        yield db
    finally:
        db.close()

crud_route_child = generic_sql_crud_router_builder(
    db_model=Child,
    prefix="/child",
    tags=["child"],
    db_session= get_transaction_session,
    sql_type=SqlType("postgresql"),
)

from fastapiquickcrud.

Avin-Techv avatar Avin-Techv commented on May 25, 2024

I am facing almost the same issue, I am also seeing local_kw in one of my api endpoint, any specific solution ?

from fastapiquickcrud.

AntonyM71 avatar AntonyM71 commented on May 25, 2024

The changes Luis suggested in #20 (comment) worked fine for me. And I've been using the libraries without issues

from fastapiquickcrud.

LuisLuii avatar LuisLuii commented on May 25, 2024

The changes Luis suggested in #20 (comment) worked fine for me. And I've been using the libraries without issues

Hi Avin, sorry for reply so late, so happy to see you are using it fine. I will suggest u to try my another crud code generator project. Which one is optimised on query and able to maintain by yourself. I have used it in few project already and working so far so good.

from fastapiquickcrud.

Related Issues (14)

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.