Fix null constraint failure when remote_addr is None and user is '{{auto}}'

Fix #229
This commit is contained in:
Klaas van Schelven
2025-09-23 10:14:28 +02:00
parent 3e0309a422
commit 16eccea851
2 changed files with 25 additions and 1 deletions

View File

@@ -167,6 +167,11 @@ def digest_tags(event_data, event, issue):
for key in "user.ip_address", "user":
if tags.get(key) == "{{auto}}":
if event.remote_addr is None:
# removing the tag if we don't have the info seems the most faithful to the semantics, i.e. if we don't
# have the information it shouldn't appear in tags.
del tags[key]
else:
tags[key] = event.remote_addr
store_tags(event, issue, tags)

View File

@@ -157,8 +157,27 @@ class DigestTagsTestCase(DjangoTestCase):
event.save()
digest_tags(event_data, event, issue)
# twice because "user" and "user.ip_address"
self.assertEqual(["123.123.123.123", "123.123.123.123"], [e.value.value for e in event.get_tags])
def test_auto_ip_address_when_not_available(self):
# could be non-available because of proxy misconfig or other reasons, in any case it should not break anything:
# Event.remote_addr is nullable so downstream code should be able to handle None
project = Project.objects.create(name="Test Project")
issue, _ = get_or_create_issue(project)
event = create_event(project, issue=issue)
event_data = {
"user": {
"ip_address": "{{auto}}",
},
}
event.remote_addr = None
event.save()
digest_tags(event_data, event, issue)
self.assertEqual([], [e.value.value for e in event.get_tags])
class SearchParserTestCase(RegularTestCase):