Bug: KeyError 'from' for `User changed from` status webhook message

Open Beginner friendly
#235 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
66/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
api

Research direction

Start in pywa/types/system.py at from_update, where the traceback shows it reads msg["from"]; compare that with the supplied user_changed_user_id webhook, which has from_user_id and system.user_id. Check nearby system update tests and run the relevant test after tracing how this webhook is parsed. Done means the sample message constructs an update without the KeyError and existing system update behavior still passes.

Written by the indexing model from the issue text.

Description

bug
Short summary

WA user id change is being handled as PhoneNumberChange

Steps to reproduce

Got two webhook messages that looked like this:

{
    "entry": [
        {
        "changes": [
            {
                "field": "'messages'", 
                "value": "{'messaging_product': 'whatsapp', 'metadata': {'display_phone_number': '5xxxx', 'phone_number_id': '3xxxx'}, 'messages': [{'from_user_id': 'MX.21xxx', 'id': 'wamid.HBxxxx', 'timestamp': '179xxx', 'system': {'body': 'User changed from CO.16xxx to MX.21xxx', 'user_id': 'MX.21xxx', 'previous_user_id': 'CO.16xxxx', 'type': 'user_changed_user_id'}, 'type': 'system'}]}"
            }
        ], 
        "id": "39xxx"
        }
    ], 
    "object": "whatsapp_business_account"
}

And pywa thrown a KeyError ([/] Failed to construct update (field=messages))

KeyError: 'from'
  File "pywa/server.py", line 405, in _call_handlers
    ].from_update(client=self, update=raw_update)
  File "pywa/types/system.py", line 71, in from_update
    wa_id=msg["from"],
Expected behavior

No response

Logs / Traceback

No response

pywa version

{"label" => "4.x (current)"}

Python version

No response

OS

No response

Minimal reproduction

No response

Additional context

No response

Dominant language
Python
Stars
598
Forks
113
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from david-lev/pywa

All issues in david-lev/pywa

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.