Jumoo / uSync.Complete.Issues

Public Issue tracker and roadmap for uSync.Complete
https://jumoo.co.uk/usync/complete/
2 stars 1 forks source link

uSync imports Content with id=0 #225

Closed bogdanvista closed 2 months ago

bogdanvista commented 3 months ago

Describe the bug I was trying to import some content and fell in a rabbit hole... All documents are imported with the ID=0 so they don't show up at all...

image

I thought maybe my DB was broken so I started from scratch and nothing imports on a new DB. I can leave you a .config content file:

<?xml version="1.0" encoding="utf-8"?>
<Content Key="4a80fe82-c7c6-42cc-a86f-e4b197dc955f" Alias="Root" Level="1">
  <Info>
    <Parent Key="00000000-0000-0000-0000-000000000000"></Parent>
    <Path>/Root</Path>
    <Trashed>false</Trashed>
    <ContentType>root</ContentType>
    <CreateDate>2021-07-21T12:53:42</CreateDate>
    <NodeName Default="Root" />
    <SortOrder>0</SortOrder>
    <Published Default="true" />
    <Schedule />
    <Template Key="43a19672-d071-4d24-a115-6e78dd4ff98d">Root</Template>
  </Info>
  <Properties>
    <gridContent>
      <Value><![CDATA[{
  "name": "1 column layout",
  "sections": [
    {
      "grid": "12",
      "rows": []
    }
  ]
}]]></Value>
    </gridContent>
  </Properties>
</Content>

Is there anything wrong with the file? Sometimes there was an error with "cannot save a non-current version". So maybe that's a clue.

Any ideas? The content files are not from the latest version of usync but when I saved something there was no difference... Maybe something that happened in the latest versions of uSync?

Thanks in advance.

Version (please complete the following information):

bogdanvista commented 3 months ago

It seems like if some content fails to import then nothing will get imported. From hundreds of content files, a few were failing to import... then Umbraco would get in a certain state... if you imported again (without a apppool recycle) you would get "cannot save a non-current version" on more content files. Somehow the content existed in cache... If I tracked down an id from the import logs.. and then added that to the CMS url (/umbraco#/content/content/edit/XXXX) then it would show... but there was nothing in the tree... I assume it lived in the cache as this behavior would disappear after an app pool recycle.

I've clean up the Content folder and reexported everything then all can be imported.

Still, I find it weird that one broken piece of content .config can prevent anything from importing.

KevinJump commented 3 months ago

Hi,

Yes very odd indeed, do you have a copy of the uSync folder that was doing this on a clean install ? i would like to take a look see if there is anything.

there are lots of caching and notifications and scopes involved when importing and maybe something gets mixed up and we can do something,

the content version thing does look like something that can happen if content is changed during a saved or published notification (e.g something listening for a save notifcation itself changes content and then saves causing another notification to happen).

uSync (v13) will also batch notifications together and in fact they can get processed in the background. this means if you have custom notifications you have to be aware of this, there can be side effects (https://docs.jumoo.co.uk/usync/uSync/guides/background)

N.B this is false by default - but the notifications do still happen in bullk (but not in the background) after a load of items have been imported .

bogdanvista commented 3 months ago

Hello,

I managed to create a uSync subset that reproduces this (I hope). There's also a missing doctype definition, but also the error with the non-current document. image

I think it should still import something regardless...

I'll send the uSync folder to info@jumoo.co.uk, is that fine? I feel it's better than posting it publicly (even though I don't think there's anything sensitive there).

KevinJump commented 2 months ago

Hi,

I've taken a look and its looks the root of the issue is caused because your uSync folder has clashing key value in it. (e.g more than one content item file with the same Key (guid) value.

you can see this if you run the uSync health check.

image

the way the error is surfacing is a little odd as we introduced a new feature in v13.1 that can merge content files together from multiple folders (roots) - but in this instance what happens is it attempts to merge together two duplicates in the same usync "folder" (e.g usync/v9/content....). when really we should throw an error.

we don't do the health check duplicate check on sync because if there are lots of files it can take a while, and would slow down all uSync operations,

but what we can do is throw an error if during the sync process we find a duplicate key in the folder we are looking into, so we've added that and will put it in the next release.

image

-- in the meantime, if you run the health check, you can find the duplicate files and manually fix them (as long as they don't have children, just changing the key value in the .config will do it.

duplicates like this shouldn't be possible to create on a single Umbraco install. as uSync will always clean up duplicate files on save of a file with a key., but they can occur if source code check-ins don't contain all the changes uSync makes, or if uSync config files are copied around the uSync folder manually - the only option then is to clean them up by hand, but the health check does help you spot them

bogdanvista commented 2 months ago

Hello,

Thank you for investigating, nice to see you found the issue and a fix.

I didn't know about the health check, never used it before, but good that I learned about that.

Yeah, I'm sure this scenario doesn't normally happen but since there are a few people working on the same project, with uSync being shared in source control, funky stuff is bound to happen.

Thanks again.