Ensure name collisions between liboverrides and their reference data does not breaks liboverrides. #110421

Closed
opened 2023-07-24 17:14:27 +02:00 by Bastien Montagne · 1 comment

The Problem

Pets production at the Blender studio as revealed an issue with library overrides, which is fairly difficult to trigger in normal usages cases, but can easily appear when production files get messy: name collision between linked reference IDs and override ones with a collection of IDs.

In practice, this is mainly affecting collections' list of objects.

At some point, given specific set of events (having several liboverrides of the same data, having several objects named the 'same' in the library file - door, door.00, door.002, etc. - and having several resyncs due to such objects being added and removed, you can end up in a situation where the override of object door.004 is named door.002, and the override of object door.002 is named door.001.

This can lead to breakage in liboverride applying code, as at some point during the process the liboverride collection can have two objects named door.002, the liboverride one, and the linked one. This breaks reference of objects of a collection by their names.

Two commits have already been made to alleviate the issue (a05419f18b and e11da03e7a), but they only make such problem much, much less likely to happen, they cannot guarantee it will never happen again.

Possible Solutions

The only way to solve this issue is to ensure that in liboverride, references to IDs within ID RNAcollections are unique and can never collide with any other ID. There can be two ways to achieve this:

  1. Replace the .001 etc. counter by some sort of alpha-numeric UID in liboverride names.
  2. Also store a reference to the library ID within liboverride operations for RNA collection items.
  3. Also store the ID pointer itself within liboverride operations for RNA collection items.

The first solution essentially introduces some concept of UUID to data-blocks, but in a poor way, potentially still brittle, and in any case fairly 'ugly' since these alphanumeric codes would be exposed everywhere in the UI.

The second solution, suggested @brecht and also discussed with @Sergey, was tried out first. From an initial analysis, it implied:

  • Adding a reference and locale Library pointer to the IDOverrideLibraryPropertyOperation. Would be null, except for RNA collection items referencing linked IDs.
    • Note that do_version code may be a bit tricky here.
  • These pointers will be initialized during the liboverride/RNA diffing process, when liboverride data is created or updated.
  • RNA collection items accessor API will need to be updated to allow search by name and libpointer for its ID items.
    • This could also be linked to existing py_rna code that allows to lookup an ID in a RNA collection of IDs by its name and library path.

However, it was actually not working for linked liboverrides, as libraries are always local IDs and never linked, this data is lost when linking the liboverride into another file. This could be worked around by storing the library as a file path oinstead of a pointer to the ID, however this would make the code significantly more complicated.

So instead, a weak reference to the ID pointer itself will be used (similar to how linked objects are referenced by local viewlayer's base data e.g.). This solution is very similar to using the Library pointer, with the key difference that ID pointers also work 'by definition' when linking liboverrides. Note that:

  • Weak reference can be used here, since it can be assumed that a linked ID referenced in that context is also used as reference of its liboverride (otherwise, something is very wrong, and getting rid of that linked reference is likely a good thing then).
  • For the same reason, there is no need for ID refcounting on these pointers.
  • While it could look like this is creating a very strong bound between a specific ID and the RNA collection item, in fact nothing changes here, since in case the ID name changes in the library, the linked reference to it are lost, so the strong bind between the ID name and the ID itself already exist de-facto in linked data.

Implemented as !110773.

# The Problem Pets production at the Blender studio as revealed an issue with library overrides, which is fairly difficult to trigger in normal usages cases, but can easily appear when production files get messy: name collision between linked reference IDs and override ones with a collection of IDs. In practice, this is mainly affecting collections' list of objects. At some point, given specific set of events (having several liboverrides of the same data, having several objects named the 'same' in the library file - `door`, `door.00`, `door.002`, etc. - and having several resyncs due to such objects being added and removed, you can end up in a situation where the override of object `door.004` is named `door.002`, and the override of object `door.002` is named `door.001`. This can lead to breakage in liboverride applying code, as at some point during the process the liboverride collection can have two objects named `door.002`, the liboverride one, and the linked one. This breaks reference of objects of a collection by their names. Two commits have already been made to alleviate the issue (a05419f18b and e11da03e7a), but they only make such problem much, much less likely to happen, they cannot guarantee it will never happen again. # Possible Solutions The only way to solve this issue is to ensure that in liboverride, references to IDs within ID RNAcollections are unique and can never collide with any other ID. There can be two ways to achieve this: 1. Replace the `.001` etc. counter by some sort of alpha-numeric UID in liboverride names. 2. Also store a reference to the library ID within liboverride operations for RNA collection items. 3. Also store the ID pointer itself within liboverride operations for RNA collection items. The first solution essentially introduces some concept of UUID to data-blocks, but in a poor way, potentially still brittle, and in any case fairly 'ugly' since these alphanumeric codes would be exposed everywhere in the UI. The second solution, suggested @brecht and also discussed with @Sergey, was tried out first. From an initial analysis, it implied: * Adding a `reference` and `locale` `Library` pointer to the `IDOverrideLibraryPropertyOperation`. Would be null, except for RNA collection items referencing linked IDs. * *Note that do_version code may be a bit tricky here.* * These pointers will be initialized during the liboverride/RNA diffing process, when liboverride data is created or updated. * RNA collection items accessor API will need to be updated to allow search by name and libpointer for its ID items. * This could also be linked to existing py_rna code that allows to lookup an ID in a RNA collection of IDs by its name and library path. However, it was actually not working for linked liboverrides, as libraries are always local IDs and never linked, this data is lost when linking the liboverride into another file. This could be worked around by storing the library as a file path oinstead of a pointer to the ID, however this would make the code significantly more complicated. So instead, a weak reference to the ID pointer itself will be used (similar to how linked objects are referenced by local viewlayer's base data e.g.). This solution is very similar to using the Library pointer, with the key difference that ID pointers also work 'by definition' when linking liboverrides. Note that: * Weak reference can be used here, since it can be assumed that a linked ID referenced in that context is also used as reference of its liboverride (otherwise, something is very wrong, and getting rid of that linked reference is likely a good thing then). * For the same reason, there is no need for ID refcounting on these pointers. * While it could look like this is creating a very strong bound between a specific ID and the RNA collection item, in fact nothing changes here, since in case the ID name changes in the library, the linked reference to it are lost, so the strong bind between the ID name and the ID itself already exist de-facto in linked data. Implemented as !110773.
Bastien Montagne added the
Type
Design
Module
Core
Status
Confirmed
Interest
Overrides
labels 2023-07-24 17:14:54 +02:00
Author
Owner

Committed as 6a86dd5f34, closing.

Committed as 6a86dd5f34, closing.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2023-08-10 12:45:26 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110421
No description provided.