Extraneous `local_kw` added to mandatory arguments in swagger
AntonyM71 opened this issue · 9 comments
Hi could you share some infomation to let me reproduce your issue? such as the SQLalchemy schema, and the code
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"),
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.
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 :)
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:xxxxx@192.168.0.xx/xxxxx")
session = sessionmaker(engine)
async_session = sessionmaker(
autocommit=False,
autoflush=False,
bind=engine,
)
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:xxxxx@192.168.0.xx/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"),
)
I am facing almost the same issue, I am also seeing local_kw in one of my api endpoint, any specific solution ?
The changes Luis suggested in #20 (comment) worked fine for me. And I've been using the libraries without issues
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.