Skip to content
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

fixing KeyError for X-Request-Id header, use X-Github-Delivery for event ID instead #2

Merged
merged 3 commits into from
Jun 1, 2022

Conversation

trz42
Copy link

@trz42 trz42 commented May 12, 2022

fixing KeyError for non-existing X-Request-Id header; apparently X-Request-ID was renamed to X-Github-Delivery

@@ -27,7 +27,7 @@ def get_event_info(request):
"""
event_info = {
'action': request.json.get('action', UNKNOWN),
'id': request.headers['X-Request-Id'],
'id': request.headers['X-Github-Delivery'],
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit puzzled by this, and X-Request-Id suddenly isn't there anymore...
Maybe that's my mistake, and I'm relying on something that's not always there in the header.

Where did you get the X-Github-Delivery from, is there a reference for that, that this uniquely identifies an event?

I'm wondering whether we should use this instead:

 'id': request.headers.get('X-Request-Id') or request.headers.get('X-Github-Delivery'),

Maybe we also need to make sure that we get proper error reporting if neither of these keys are available?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on https://apievangelist.com/2017/09/13/webhook-delivery-headers-from-github-api/, X-GitHub-Delivery indeed seems to be the correct field to use to get a unique ID for the event

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I logged the HTTP headers and compared their values with the "Event ID" shown on the smee.io/channel page. I don't know if there is a reference.

Apparently, both headers may be valid, see octokit/webhooks.js#579 Don't know if they can be present both in a single request. Your suggestion to use one of the headers might be the right way to go forward.

Copy link
Author

@trz42 trz42 May 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, the X-Request-Id was not present in my limited tests only triggering installation events.

@boegel
Copy link
Owner

boegel commented May 13, 2022

@trz42 Tests are failing because there it's still assumed that only providing X-Request-Id in the event header is sufficient; see tests/event_data.py and tests/test_events.py

@boegel boegel changed the title fixing KeyError for X-Request-Id header fixing KeyError for X-Request-Id header, use X-Github-Delivery for event ID instead Jun 1, 2022
@boegel boegel merged commit 853079b into boegel:main Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants