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

fix(dao): use explicit id filter #23246

Merged
merged 1 commit into from
Mar 1, 2023
Merged
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
4 changes: 2 additions & 2 deletions superset/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def find_by_id(
query = cls.base_filter( # pylint: disable=not-callable
cls.id_column_name, data_model
).apply(query, None)
id_filter = {cls.id_column_name: model_id}
id_column = getattr(cls.model_cls, cls.id_column_name)
try:
return query.filter_by(**id_filter).one_or_none()
return query.filter(id_column == model_id).one_or_none()
except StatementError:
# can happen if int is passed instead of a string or similar
return None
Expand Down
18 changes: 11 additions & 7 deletions tests/integration_tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,17 +609,21 @@ def test_update_chart_new_owner_not_admin(self):
"""
Chart API: Test update set new owner implicitly adds logged in owner
"""
gamma = self.get_user("gamma")
gamma = self.get_user("gamma_no_csv")
alpha = self.get_user("alpha")
chart_id = self.insert_chart("title", [alpha.id], 1).id
chart_data = {"slice_name": "title1_changed", "owners": [gamma.id]}
self.login(username="alpha")
chart_id = self.insert_chart("title", [gamma.id], 1).id
chart_data = {
"slice_name": (new_name := "title1_changed"),
"owners": [alpha.id],
}
self.login(username=gamma.username)
uri = f"api/v1/chart/{chart_id}"
rv = self.put_assert_metric(uri, chart_data, "put")
self.assertEqual(rv.status_code, 200)
assert rv.status_code == 200
model = db.session.query(Slice).get(chart_id)
self.assertIn(alpha, model.owners)
self.assertIn(gamma, model.owners)
assert model.slice_name == new_name
assert alpha in model.owners
assert gamma in model.owners
db.session.delete(model)
db.session.commit()

Expand Down