Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion flask_admin/contrib/sqla/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,13 @@ def get_one(self, id):
Model id
"""
session = _get_deprecated_session(self.session)
return session.get(self.model, tools.iterdecode(id))
_id = tools.iterdecode(id)
if isinstance(self._primary_key, tuple):
_id = tools.iterdecode(id)
else:
_id = (tools.escape(id),)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why tools.escape?
Looks unnecessary to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, what if the actual string-single-PK="1,2", is it possible to navigate /admin/details?id=1,2 without escaping ?


return session.get(self.model, _id)

# Error handler
def handle_view_exception(self, exc: Exception) -> bool:
Expand Down
10 changes: 10 additions & 0 deletions flask_admin/tests/sqla/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,16 @@ def test_details_view(app, db, admin, session_or_db):
assert "test2_val_1" in data
assert "test1_val_1" in data

# test single-PK with multiple IDs in query string
rv = client.get(
"/admin/model2/details/?url=%2Fadmin%2Fmodel2%2F&id=1,2",
follow_redirects=True,
)
data = rv.data.decode("utf-8")
assert "String Field" in data
assert "test2_val_1" in data
assert "test1_val_1" in data

# test column_details_list
rv = client.get("/admin/sf_view/details/?url=%2Fadmin%2Fsf_view%2F&id=1")
data = rv.data.decode("utf-8")
Expand Down