Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Handle create=false when exact matching
Browse files Browse the repository at this point in the history
When a facility list item is submitted with create=false and there is
no match found, a FacilityListItem is created with facility_id=None.
When another facility list item is submitted which exact matches that
FacilityListItem, an error was being thrown. Instead, we now filter
out FacilityListItems where the facility_id=None, allowing us to match
to the next best option (if one exists) or pass the FacilityListItem
on to the dedupe process.
  • Loading branch information
TaiWilkin committed Jan 18, 2022
1 parent 3e4d5e4 commit 6ed063a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/django/api/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def exact_match_items(messy, contributor):

matched_items = FacilityListItem.objects \
.filter(status__in=[FacilityListItem.MATCHED,
FacilityListItem.CONFIRMED_MATCH])
FacilityListItem.CONFIRMED_MATCH]) \
.exclude(facility_id=None)
active_item_ids = FacilityMatch.objects \
.filter(status__in=[FacilityMatch.AUTOMATIC,
FacilityMatch.CONFIRMED,
Expand Down
8 changes: 8 additions & 0 deletions src/django/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6026,6 +6026,14 @@ def test_creates_nonstandard_fields(self):
self.assertEquals(1, len(fields))
self.assertIn('extra_1', fields)

def test_exact_matches_with_create_false(self):
self.join_group_and_login()
url_with_query = '{}?create=false&public=true'.format(self.url)
response = self.client.post(url_with_query, self.valid_facility)
self.assertEqual(response.status_code, 200)
response_two = self.client.post(url_with_query, self.valid_facility)
self.assertEqual(response_two.status_code, 200)


class FacilityCreateBodySerializerTest(TestCase):
def test_valid_data(self):
Expand Down

0 comments on commit 6ed063a

Please sign in to comment.