fix(contacts): add view action, show phones in list, preserve fields on update#4748
fix(contacts): add view action, show phones in list, preserve fields on update#4748holden093 wants to merge 3 commits into
Conversation
vdmkenny
left a comment
There was a problem hiding this comment.
Good direction (phones in list, the view action, and preserving fields on rename are all real gaps), but the preserve logic still loses data on partial single-field updates, which is the common case it is meant to cover.
The existing-contact fetch only runs when emails, email, and phones are all absent:
existing = None
if "emails" not in args and "email" not in args and "phones" not in args:
rows = await asyncio.to_thread(cc._fetch_contacts)
existing = next((r for r in rows if r.get("uid") == uid), None)
...
if "phones" in args:
phones = [...]
else:
phones = list(existing.get("phones") or []) if existing else []So update {uid, emails:["new@x"]} with no phones takes the else branch while existing is still None, and phones get wiped. Same in reverse: passing only phones wipes the emails. The data loss it claims to prevent still happens whenever the caller updates one of the two fields.
Fix: fetch existing whenever either field is missing (or just always on update), then fall back per-field independently:
existing = None
if "emails" not in args and "email" not in args or "phones" not in args:
rows = await asyncio.to_thread(cc._fetch_contacts, True)
existing = next((r for r in rows if r.get("uid") == uid), None)Two smaller things:
- The preserve fetch uses
_fetch_contacts()(cache,force=False), so a contact added moments earlier may be missing from the cache, givingexisting=Noneand the same wipe.viewalready passesforce=True; do the same here. - Please add a test: rename-only keeps both emails and phones; updating only emails keeps the existing phones (and vice versa). That pins exactly this bug.
list/view/phones changes are fine as-is.
f34a75e to
aed606e
Compare
|
Addressed all three issues, @vdmkenny:
|
74ed6f0 to
3ac0876
Compare
…on update
- Add 'view' action to manage_contact: fetch a single contact by UID and
display name, UID, emails, phones, and address.
- Show phone numbers in 'list' output alongside emails.
- Preserve existing emails/phones during partial update (rename-only,
single-field updates) by fetching the current contact when either
field is missing. Uses force=True on _fetch_contacts to avoid a stale
cache masking a just-added contact.
- Fix the preserve guard: use OR instead of AND so single-field updates
like {uid, emails:[new]} don't wipe phones and vice versa.
3ac0876 to
e893d14
Compare
Summary
Fixes three gaps in the
manage_contactsagent tool that made phone-number workflows unreliable:listnow includes phone numbers, a newviewaction returns full contact details by UID, andupdatepreserves existing emails/phones when the caller doesn't pass them (preventing data loss on partial edits like renaming).Target branch
dev, notmain.Linked Issue
Fixes #4747
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.How to Test
Visual / UI changes
None — backend-only change.