-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow accessing source object model in sync_to/sync_from #199
Comments
In this case, I would make AttachmentData its own model, and make it a child of Attachment. You would then either pass the identifier of Attachment to AttachmentData. This would ensure that you have that data available when you need it. I am making assumption that you can then do something like api/attachments/?name= within your AttachmentData create and update class in order to lookup the id of Attachment. The Adapter will then handle separating the Attachment from AttachmentData and handling the child relationship. |
Hi @smk4664, Thank you for the quick reply. I'm trying to figure out what you're describing here. I'll postfix everything with either A or B when discussing this. Suppose I have AttachmentA with the If I do a
|
Ah yes, AttachmentData could be a list then, so you would create multiple items, like you would interfaces on a device. In your instance of Attachment A has 5 AttachmentData items, and you do a sync_to(B), it will produce a diff of only the changes. So, Attachment B has 4 AttachmentData items the diff will only show the AttachmentData that does not match. |
Can you look up |
Now I understand what you meant and it is actually what I'm doing right now. class Attachment(DiffSyncModel):
_modelname = "attachment"
_identifiers = ("name",)
_shortname = ()
_attributes = (
"jira_id",
"cust_id",
)
_children = {}
id: str
jira_id: str | None
cust_id: str
name: str
class Issue(DiffSyncModel):
_modelname = "issue"
_identifiers = ("jira_id", "cust_id")
_shortname = ()
_attributes = ()
_children = {"attachment": "attachments"}
jira_id: str | None
cust_id: str
attachments: list[Attachment] = [] And looking up the For now this seems to work: jira = JiraAdapter()
jira.load()
cust = CustAdapter()
cust.load()
diff_c_j = cust.diff_to(jira, flags=DiffSyncFlags.SKIP_UNMATCHED_DST)
for i in diff_c_j.children["issue"].values():
for j in i.child_diff.children["attachment"].values():
j.source_attrs["source"] = cust.get(Attachment, j.name)
cust.sync_to(jira, flags=DiffSyncFlags.SKIP_UNMATCHED_DST, diff=diff_c_j) The create function then looks like this: class JiraAttachment(Attachment):
"""Extend the Attachment object to store Jira specific information."""
@classmethod
def create(cls, diffsync: DiffSync, ids, attrs: dict):
source: Attachment = attrs.pop("source")
[call to get attachment data from remote system based on source.id] |
@draggeta anything else needed from the diffsync side or is this clear now? |
Hi @Kircheneer, it would be a nice feature to have, but this workaround suffices. Thank you for the help :) |
Environment
Proposed Functionality
Similar I believe to #60.
Have the entire data model of the source available for create and update calls to the remote system.
Use Case
We currently want to sync some data between ITSM systems. ITSM A and B returns a list of available attachments, but not the data within. I can compare based on the data returned which attachments exists on both sides and compare. The used model is:
I do not want to compare on the
id
as they are only locally significant. However, to get the attachment content, I need theid
. If you do a sync from A to B, thatid
becomes necessary, but the id of A is not available in the create function attributes or somewhere else.As a workaround I edited the above class:
I create a diff and then edit, in a loop, the diff
data
property to include theid
of A. In the create function for B I can then perform a call to the A source system to get the data and sync it.Is there a better way to do this, where the source class or data is available in it's entirety?
The text was updated successfully, but these errors were encountered: