Skip to content

Commit 3c4a453

Browse files
Merge pull request #1110 from hinashi/fixed/edit_entity_apiv2
Fixed entity editing failing for non created user
2 parents fc96616 + dbfcb7f commit 3c4a453

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

entity/api_v2/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def _update_or_create(
214214

215215
entity: Entity
216216
entity, is_created_entity = Entity.objects.get_or_create(
217-
id=entity_id, created_user=user, defaults={**validated_data}
217+
id=entity_id, defaults={**validated_data}
218218
)
219219
if not is_created_entity:
220220
# record history for specific fields on update

entity/tests/test_api_v2.py

+19
Original file line numberDiff line numberDiff line change
@@ -2631,6 +2631,25 @@ def test_update_entity_without_permission(self):
26312631
)
26322632
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
26332633

2634+
@mock.patch("entity.tasks.edit_entity_v2.delay", mock.Mock(side_effect=tasks.edit_entity_v2))
2635+
def test_update_entity_with_other_created_user(self):
2636+
self.admin_login()
2637+
2638+
params = {
2639+
"id": self.entity.id,
2640+
"name": "change-entity",
2641+
"note": "change-hoge",
2642+
}
2643+
2644+
resp = self.client.put(
2645+
"/entity/api/v2/%d/" % self.entity.id, json.dumps(params), "application/json"
2646+
)
2647+
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
2648+
2649+
self.entity.refresh_from_db()
2650+
self.assertEqual(self.entity.name, "change-entity")
2651+
self.assertEqual(self.entity.note, "change-hoge")
2652+
26342653
def test_update_entity_with_webhook_is_disabled(self):
26352654
entity: Entity = self.create_entity(
26362655
**{

0 commit comments

Comments
 (0)