Skip to content

Fix/atrribute error crash when no postal info supplied#265

Merged
ehsan-fj merged 2 commits intoInternetNZ:developfrom
yuriverweij:fix/atrributeError-crash-when-no-postal_info-supplied
Mar 10, 2026
Merged

Fix/atrribute error crash when no postal info supplied#265
ehsan-fj merged 2 commits intoInternetNZ:developfrom
yuriverweij:fix/atrributeError-crash-when-no-postal_info-supplied

Conversation

@yuriverweij
Copy link
Copy Markdown
Contributor

Fix AttributeError in Contact.update() when postal_info=None

Problem

Calling Contact.update() with a ContactData where postal_info is None (the default) raised an AttributeError in two places:

  1. _data_to_dict() — called .pop("address", {}) directly on postal_info without guarding against None
  2. update() — accessed contact.postal_info.address unconditionally when computing address_change

Changes

pyepp/contact.py

  • _data_to_dict: guard postal_info.pop(...) with if postal_info is not None
  • update: use short-circuit evaluation bool(contact.postal_info and contact.postal_info.address) for address_change

tests/test_contact.py

  • Added test_data_to_dict_without_postal_info — verifies _data_to_dict handles postal_info=None without crashing and omits postal fields from the result
  • Added test_update_without_postal_info — regression test asserting postalinfo_change=False and address_change=False are passed to execute when postal_info=None
  • Strengthened existing test_update to assert postalinfo_change=True is passed to execute

@yuriverweij
Copy link
Copy Markdown
Contributor Author

Linting:
Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)
All unit tests also pass.

Copy link
Copy Markdown
Member

@ehsan-fj ehsan-fj left a comment

Choose a reason for hiding this comment

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

Great, thanks 🚀

@ehsan-fj ehsan-fj merged commit ace3814 into InternetNZ:develop Mar 10, 2026
1 check passed
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.

2 participants