Skip to content

fix: prevent absolute image paths from being written to save files#99

Open
beneaze wants to merge 1 commit into
mainfrom
fix/no-absolute-image-paths-in-save
Open

fix: prevent absolute image paths from being written to save files#99
beneaze wants to merge 1 commit into
mainfrom
fix/no-absolute-image-paths-in-save

Conversation

@beneaze

@beneaze beneaze commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

  • serialize_component was writing raw absolute paths to image_path in save files whenever a component's image lived outside both the built-in package and all configured libraries
  • to_relative_path() explicitly falls back to returning the absolute path for such images, and the old code used its return value unconditionally
  • Fix: check Path(rel_path).is_absolute() after the call and leave image_path_serialized as "" if still absolute — no absolute paths ever reach the save file

Also removes a dead-code inner if rec.image_path / else: "" branch (unreachable since the outer guard already ensures rec.image_path is truthy).

Serialization priority (unchanged except last step)

Case Stored as
Image in a configured library @library/{lib}/{component}/...
Image in the package (built-ins) package-relative path
Image outside both "" (was: absolute path)

Test plan

  • Run pytest tests/core/test_component_record.py — all 14 tests pass
  • Open a scene with a custom component whose image is in the user library, save and reload — image still loads via @library/... path
  • Open a scene with a component whose image is outside all libraries, save — confirm image_path is "" in the JSON rather than an absolute path

🤖 Generated with Claude Code

When a component image lives outside both the package and all configured
libraries, to_relative_path() returned the absolute path unchanged, which
was then blindly written to image_path in the save file.  Absolute paths
break portability — the file stops working on any other machine or after
a home-directory move.

The fix checks whether to_relative_path()'s result is still absolute and,
if so, leaves image_path_serialized as "" rather than writing the absolute
path.  Priority is unchanged: @library/... > package-relative > "".

The old inner `if rec.image_path / else: ""` branch was dead code (the
outer guard already ensures rec.image_path is truthy) and is removed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant