Comments (7)
File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\api\frameworks\fastapi\api.py", line 329, in configuration
return await api_service.get_configuration(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\api\service.py", line 414, in get_configuration
current_user_id = await get_user_id_from_session_id(session_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\api\service.py", line 62, in get_user_id_from_session_id
if not user_id or not await admin_model.get_obj(user_id):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\models\base.py", line 415, in get_obj
obj = await self.orm_get_obj(id)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Владислав\PycharmProjects\mitsu_api\virtualenv\Lib\site-packages\fastadmin\models\orms\sqlalchemy.py", line 314, in orm_get_obj
return await session.get(self.model_cls, id)
from fastadmin.
Investigation:
- we get configuration after sign in to render UI
- we get current_user_id from session (jwt token which we store in http only cookies)
current_user_id = await get_user_id_from_session_id(session_id) (fastadmin\api\service.py, line 447)
In get_user_id_from_session_id:
user_id = convert_id(user_id)
if not user_id or not await admin_model.get_obj(user_id):
return None
After a fix in 0.1.37 we have convert_id and get_obj should receive int | UUID not string
get_obj -> orm_get_obj (SQL Alchemy orm)
async def orm_get_obj(self, id: UUID | int) -> Any | None:
sessionmaker = self.get_sessionmaker()
async with sessionmaker() as session:
return await session.get(self.model_cls, id)
from fastadmin.
My suggestion is to change the code >>https://github.com/vsdudakov/fastadmin/blob/f618ac98f8f50f5cddf835139ca626fe6c2e7/fastadmin/api/service.py#L121:
"user_id": str(user_id),
To:
"user_id": user_id,
And add this code before return:
if isinstance(user_id, UUID) :
user_id = str(user_id)
I will try the solution. Thank you!
from fastadmin.
0.1.37...0.1.38
@kuyugama Provided your solution in 0.1.38. Hope it will help.
from fastadmin.
Investigation:
- we get configuration after sign in to render UI
- we get current_user_id from session (jwt token which we store in http only cookies)
current_user_id = await get_user_id_from_session_id(session_id) (fastadmin\api\service.py, line 447)In get_user_id_from_session_id:
user_id = convert_id(user_id) if not user_id or not await admin_model.get_obj(user_id): return None
After a fix in 0.1.37 we have convert_id and get_obj should receive int | UUID not string
get_obj -> orm_get_obj (SQL Alchemy orm)
async def orm_get_obj(self, id: UUID | int) -> Any | None: sessionmaker = self.get_sessionmaker() async with sessionmaker() as session: return await session.get(self.model_cls, id)
Converting id to a number after it has been converted to a string is a bad decision. Because you can store id already in the desired data type
from fastadmin.
Agreed but it doesn't work for UUID , could you please check 0.1.38?
from fastadmin.
In case it works I will clean up code and remove convert_id keep it only for UUID may be
from fastadmin.
Related Issues (20)
- Failed to run FastAPI Framework without flask installed HOT 1
- bash: export: `=': not a valid identifier HOT 1
- Django ORM implementation
- Remove pydantic dependency HOT 1
- Fix identification fk_name for inlines
- Fix upload widget and logic here
- UrlField widget type
- GeoField widget type HOT 2
- JSONField widget type (TextArea)
- PhoneField widget type
- Update documentation (Auto generate it)
- Admin panel crashes when signing in. HOT 3
- "TEST-1" - is identified as datetime on js side
- Capitalise all words for field labels
- Add peewee orm integration
- Remove pydantic from toml
- field_name_id fields with postfix _id do not show on admin
- How to get obj asynchronously in "has_xxx_permission" synchronous method HOT 2
- Deploy project HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastadmin.