Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot edit item #364

Closed
2 tasks done
junoriosity opened this issue Oct 30, 2022 · 8 comments
Closed
2 tasks done

Cannot edit item #364

junoriosity opened this issue Oct 30, 2022 · 8 comments

Comments

@junoriosity
Copy link

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

I would like to edit in my database, yet when I click on the edit button I get an Internal Server Error with the following server error message

...
api-web-1  |   File "/usr/local/lib/python3.10/site-packages/sqladmin/helpers.py", line 118, in get_primary_key
api-web-1  |     assert len(pks) == 1, "Multiple Primary Keys not supported."
api-web-1  | AssertionError: Multiple Primary Keys not supported.

Do you know how to fix it?

Steps to reproduce the bug

class User(SQLModel, table=True):
    user_id: str = Field(primary_key=True, nullable=False)
    e_mail: EmailStr

class UserAdmin(ModelView, model=User):
    column_list = [User.user_id]
    column_searchable_list = [User.user_id]

admin = Admin(app, engine)

admin.add_view(UserAdmin)

Expected behavior

No response

Actual behavior

No response

Debugging material

No response

Environment

  • MacOS
  • Python 3.10
  • SQLAdmin 0.6.1

Additional context

No response

@su-shubham
Copy link

#63
No multiple PK support.

@junoriosity
Copy link
Author

@su-shubham Many thanks for getting back to me. The strange thing is, however, that I do have just one primary key.

@su-shubham
Copy link

su-shubham commented Oct 31, 2022

@junoriosity It works fine if you have one primary key but multiple PK still not supported in sql admin.
As error says that you might implement multiple PK in one models so that's making an actual issue To avoid the error don't include the model in Sqladmin .

@junoriosity
Copy link
Author

@su-shubham As you can see my current model just consists of one primary key ... and actually just one field at all.

@aminalaee
Copy link
Owner

aminalaee commented Oct 31, 2022

Thank you both, as you can see here the line:

pks = inspect(model).mapper.primary_key
assert len(pks) == 1, "Multiple Primary Keys not supported."
return pks[0]
this is coming from SQLAlchemy inspection, so your model should definitely have multiple PKs or that SQLAlchemy is somehow confused about your model.
In any case I don't think there's much to be done here.

@su-shubham
Copy link

@aminalaee Can I achieve it if I have composite key in one model.

@aminalaee
Copy link
Owner

TBH I have not tried it but I think it should work. Depends on how SQLAlchemy would inspect that.

@aminalaee
Copy link
Owner

Closing it due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants