Skip to content

Fix KeyError: 'fbtrace_id' for ActionSource.APP with SafeEventRequestAsync#723

Open
dkranchii wants to merge 1 commit intomainfrom
bug_fix_key_error
Open

Fix KeyError: 'fbtrace_id' for ActionSource.APP with SafeEventRequestAsync#723
dkranchii wants to merge 1 commit intomainfrom
bug_fix_key_error

Conversation

@dkranchii
Copy link

What does this PR do?

  • Adds a robust wrapper (SafeEventRequestAsync) to handle the KeyError: 'fbtrace_id' that occurs when sending events with ActionSource.APP in the Facebook Python Business SDK.
  • If the API response is missing fbtrace_id, the wrapper returns a safe fallback EventResponse, preventing crashes.
  • No core SDK files are changed; this is a drop-in, non-breaking fix.
  • Includes a test script to verify the patch.

Why is this needed?

When using ActionSource.APP, the Facebook API sometimes omits the fbtrace_id field, causing the SDK to raise a KeyError and crash. This patch ensures robust handling of this scenario.

How to use

from facebook_business.utils.safe_serverside import SafeEventRequestAsync

request = SafeEventRequestAsync(events=[event], pixel_id=pixel_id)
response = await request.execute()

…Async

- Adds SafeEventRequestAsync wrapper to gracefully handle missing fbtrace_id in API responses when using ActionSource.APP.
- Prevents crashes by returning a fallback EventResponse if fbtrace_id is missing.
- No changes to core SDK files; this is a drop-in, non-breaking fix.
- Includes test script to verify the patch.
(Artifact 1. ID=[CNKG] Type=\"text\" Title=\"Facebook Python Business SDK: Solving KeyError 'fbtrace_id' with ActionSource.APP\")
@meta-cla meta-cla bot added the CLA Signed label Feb 11, 2026
@dkranchii
Copy link
Author

Results:
Screenshot 2026-02-11 at 4 26 24 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant