Skip to content

move log_sync_status calls until after object creation. - #379

Open
Kircheneer wants to merge 3 commits into
networktocode:developfrom
Kircheneer:move-sync-status-logging
Open

Kircheneer wants to merge 3 commits into
networktocode:developfrom
Kircheneer:move-sync-status-logging

Conversation

@Kircheneer

Copy link
Copy Markdown
Contributor

Note: I used AI to help research and make this change.

DiffSync currently logs creation before adding the new object to its target store, preventing log consumers such as Nautobot SSoT from accessing newly created objects. Logging after insertion makes the object available for linking creation logs to the corresponding record.

Here is a little call graph to illustrate this:

sync_diff_element()
├─ sync_model()
│ └─ Model.create() → new model
│ └─ creation log ← previously here
├─ target.add(new_model)
├─ creation log ← now here
│ └─ SSoT lookup_object()
│ └─ target.get(type, unique_id) ← object is now available
└─ synchronize children

The goal is to eventually make it possible to let lookup_object in SSoT always populate the synced_object_id in the SyncLogEntry, even at creation time, and without workarounds/performance issues.

DiffSync currently logs creation before adding the new object to its target store, preventing log consumers such as Nautobot SSoT from accessing newly created objects. Logging after insertion makes the object available for linking creation logs to the corresponding record.

Here is a little call graph to illustrate this:

sync_diff_element()
├─ sync_model()
│  └─ Model.create() → new model
│     └─ creation log                 ← previously here
├─ target.add(new_model)
├─ creation log                       ← now here
│  └─ SSoT lookup_object()
│     └─ target.get(type, unique_id)   ← object is now available
└─ synchronize children
@Kircheneer
Kircheneer force-pushed the move-sync-status-logging branch from 1df52ae to 0d0d0c2 Compare November 30, 2026 10:05
Comment thread tests/unit/test_create_log_ordering.py Outdated
Comment on lines +114 to +115
assert events[0]["status"] == "error"
assert events[0]["event"] == "backend rejected creation"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's not obvious to me why some of the events assertions are implemented inside def observe(event) while others are implemented separately, as here. What was the decision process?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My apologies for the renewed slop. I have reverted to what I would have tested if I had turned on my brain, which is just the new behaviour. I feel like what I now have is useful.

glennmatthews
glennmatthews previously approved these changes Nov 30, 2026

@glennmatthews glennmatthews left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix seems reasonable to me, though it feels inelegant to move from one central call site for log_sync_status to two conditional ones, I think I can understand why it was needed.

This branch has not been deployed

No deployments
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