-
Notifications
You must be signed in to change notification settings - Fork 548
fix: Ensure tags values are strings #4459
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
base: potel-base
Are you sure you want to change the base?
fix: Ensure tags values are strings #4459
Conversation
❌ Unsupported file formatUpload processing failed due to unsupported file format. Please review the parser error message:
For more help, visit our troubleshooting guide. ❌ 476 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Looks like tests are failing because the non-string values were being asserted in the test suites |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some high-level thoughts:
- We seem to be stringifying the tags in multiple places. Do we need to do it in all of those? Is there a way to centralize it, e.g. move it to the end of the pipeline, e.g. in the serializer?
- Are we sure we're not changing anything user-facing, especially in callbacks? (E.g. if a user is accessing tags in a
before_send
or similar.)
def test_set_tag_handles_conversion_failure(): | ||
"""Test that set_tag handles objects that fail to convert to string.""" | ||
scope = Scope() | ||
|
||
# Create an object that raises an exception when str() is called | ||
class BadObject: | ||
def __str__(self): | ||
raise Exception("Cannot convert to string") | ||
|
||
def __repr__(self): | ||
return "BadObject()" | ||
|
||
bad_obj = BadObject() | ||
|
||
# This should not raise an exception | ||
scope.set_tag("bad_object", bad_obj) | ||
|
||
# The tag should be set with the repr value | ||
event = scope.apply_to_event({}, {}) | ||
tags = event.get("tags", {}) | ||
|
||
assert tags["bad_object"] == "BadObject()", "Tag should be set with repr value" | ||
|
||
|
||
def test_set_tags_handles_conversion_failure(): | ||
"""Test that set_tags handles objects that fail to convert to string.""" | ||
scope = Scope() | ||
|
||
# Create an object that raises an exception when str() is called | ||
class BadObject: | ||
def __str__(self): | ||
raise Exception("Cannot convert to string") | ||
|
||
def __repr__(self): | ||
return "BadObject()" | ||
|
||
bad_obj = BadObject() | ||
|
||
scope.set_tags( | ||
{ | ||
"good_tag1": "value1", | ||
"bad_tag": bad_obj, | ||
"good_tag2": 123, | ||
} | ||
) | ||
|
||
event = scope.apply_to_event({}, {}) | ||
tags = event.get("tags", {}) | ||
|
||
assert tags["good_tag1"] == "value1" | ||
assert tags["bad_tag"] == "BadObject()", "Tag should be set with repr value" | ||
assert tags["good_tag2"] == "123" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe consolidate these two test cases into one?
We discussed offline, but here's the summary:
|
Re: 2: Thought about this some more. The thing about expected behavior is that it doesn't really matter if it's technically incorrect -- users come to expect it and depend on it, and we need to take that into account. Especially in this case as the event is technically part of the public API in Another reason I'm reluctant to do this in a minor version is that in general it's hard to notice errors in a What we can do:
Doing this on |
@sentrivana I guess then there's also the question of whether we should fix this at all. The use case is pretty edge-case; if your premise is correct that folks are relying on the "incorrectly typed" tag values, then making the change in the major would also be disruptive, right? What do you think? |
Some disruption is to be expected when upgrading to a new major version. As long as we document this properly (changelog, migration guide in repo, migration guide in docs) we're good. |
16045df
to
4721438
Compare
a78a060
to
28eaca8
Compare
Ensure tag values are strings before serializing an event or a transaction to an Event dictionary. Fixes #4391
28eaca8
to
bce0694
Compare
@sentrivana I rebased on |
Ensure tag values are strings before serializing an event or a transaction to an
Event
dictionary.Fixes #4391