custom action in example not working
Checklist
- [x] The bug is reproducible against the latest release or
master. - [x] There are no similar issues or pull requests to fix it yet.
Describe the bug
In example https://aminalaee.dev/sqladmin/configurations/#custom-action
function get_object_for_edit is called with param pk
but definition waits for request object:
async def get_object_for_edit(self, request: Request)
and it looks for for path_param 'pk' in request not 'pks'
Steps to reproduce the bug
Use example in https://aminalaee.dev/sqladmin/configurations/#custom-action
Expected behavior
No response
Actual behavior
Error
Debugging material
No response
Environment
any/3.12/last
Additional context
No response
I've had the same problem
I am facing the same problem. The solution for me was to call self.session_maker() in the context manager and use my repo to get the object instead of using the get_object_for_edit() function:
async def reset_password(self, request: Request):
pks = request.query_params.get("pks", "").split(",")
if pks:
for pk in pks:
async with self.session_maker() as session:
model = await user_crud.get_one(session, int(pk))
...
I think this situation is related to this accepted pull-request
The edit_form_query implementation tries to analyze path_params to get pk, while the documentation tells us to pass pk from the pks contained in query_params there.
I used function get_object_for_details() instead of get_object_for_edit()
Hi there! Same here. I solved it implementing a new method on my ModelView:
async def get_object(self, value):
stmt = self._stmt_by_identifier(value)
return await self._get_object_by_pk(stmt)
And calling it when needed. I've prefered that rather than overriding existing base functionalities because I can customize the method without touching shared logic.