-
Notifications
You must be signed in to change notification settings - Fork 398
fix(graphql): handle nil value for locations in unified_trace #5025
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: master
Are you sure you want to change the base?
fix(graphql): handle nil value for locations in unified_trace #5025
Conversation
f3a2709 to
04a7bc3
Compare
|
Hey @codella, thanks for spotting this and sending a fix our way! If you happen to have the stack trace of one of those |
Hey! Thanks for being so snappy! 😲 I updated the description with the stack trace 🚀 |
|
@ivoanjo maybe you can help me. I am running the GraphQL tests with |
04a7bc3 to
dad0df2
Compare
|
Ah, I think you want I believe we have them separate because this functionality depends on modern graphql gem versions, yet we still want to support (and test with) the old ones. |
|
@ivoanjo I've been spending some time trying to add a test in Do you have any pointers, or alternative ways to write a test for it? I'm a bit puzzled that I couldn't get a test to replicate the issue, given that |
|
Good question... I spent a few minutes looking into the graphql gem and our tests and how we may trigger the issue to then test the fix, and I also couldn't trigger the error. TBH I think the fact that this is proving hard to test via that route is suggesting to me that it's not the right way to go, given what we want to test here. Specifically, we want to test that some specific query in some situation doesn't break. But if this case is possible (you've definitely seen it in production) but awkward to trigger (we've both not had success at this), I'm thinking even if we find a way to trigger the situation on the current gem version, what if in a future version, the error actually is slightly different, and maybe doesn't trigger in the same way, the dd-trace-rb test may start passing for the wrong reasons (doesn't break -- but perhaps not because the code isn't testing for nil). TL;DR My suggestion here is moving away from integration testing and into a simpler unit test: one that directly tests |
aed7728 to
a5b2bf6
Compare
|
@ivoanjo alright, I extracted both |
Hmmm, to be honest I'm not the biggest fan of how it looks in this version because the What do you think of going back to the previous state, and making Another useful thing to adjust is def serialize_error_locations: (Array[Hash[String, Integer]]? locations) -> Array[String]
# or in my suggested version
def self.serialize_error_locations: (Array[Hash[String, Integer]]? locations) -> Array[String]then the typechecker also starts complaining if the code doesn't deal with WDYT? 😄 |
35e5cc2 to
399dcef
Compare
399dcef to
169c10f
Compare
|
@ivoanjo super legit suggestion! I implemented it as you said--let me know if I missed anything! |
ivoanjo
left a comment
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.
👍 Perfect, thank you!
Merging this may take a bit on our side -- I'll be out for a few days + our current setup needs some manual prodding of CI for community contributions. But I'll make sure this gets included in the upcoming v2.23! :)
|
Thank you @ivoanjo for your help getting this right! |
What does this PR do?
It then adds a pre-condition check in
serialize_error_locationsto handle the case when the provided argumentlocationsisnil, and makesserialize_error_locationsa class method for testability.Motivation:
The logic in
serialize_error_locationsassumes thatlocationsis always present in the Hash returned by::GraphQL::Error#to_h, but in reality is only present when if the error can be associated to an AST node (ref). This results in occasionalNoMethodErrors being raised by applications using this gem.Change log entry
Yes. Tracing: Fix NoMethodError in graphql integration when error has no locations. (Added by @ivoanjo)
Additional Notes:
Stack Trace:
How to test the change?
I was expecting
bundle exec rake test:graphqlto cover the code changes made incontrib/graphql/unified_trace.rb, but it looks like that's not the case. Any suggestions on how to proceed or how to add the necessary code coverage are very welcome!