darktable-org / darktable

darktable is an open source photography workflow application and raw developer
https://www.darktable.org
GNU General Public License v3.0
9.68k stars 1.13k forks source link

composite: can create loops #17622

Open kofa73 opened 1 week ago

kofa73 commented 1 week ago

Describe the bug

It is not possible to set image A as an overlay of B, and then set B as an overlay of A, but with 3 images, this is possible:

$ sqlite3 ~/.config/darktable/library.db
SQLite version 3.45.1 2024-01-30 16:01:20
Enter ".help" for usage hints.
sqlite> select * from overlay;
12285|12288
12288|12289
12289|12285

Maybe a recursive query could be used: https://sqlite.org/lang_with.html#recursive_common_table_expressions Or, a simpler (but more restrictive) solution: don't allow setting an image as an overlay, if it has its own overlay; also, disallow setting an overlay on an image that is already used as an overlay (so if its ID appears in either the imgid or in the overlay_id column).

BTW, shouldn't there be an FK referential integrity constraint be defined for overlay_id (referencing images(id))? And an index on the column?

Steps to reproduce

Use any 3 images:

  1. set the 2nd image as the overlay of the 1st
  2. set the 3rd image as the overlay of the 2nd
  3. set the 1st image as the overlay of the 3rd

Expected behavior

dt should prevent such loops

Logfile | Screenshot | Screencast

No response

Commit

No response

Where did you obtain darktable from?

downloaded from www.darktable.org

darktable version

4.9.0+721~g963cb7e26b

What OS are you using?

Linux

What is the version of your OS?

Ubuntu 24.04

Describe your system?

No response

Are you using OpenCL GPU in darktable?

No

If yes, what is the GPU card and driver?

irrelevant

Please provide additional context if applicable. You can attach files too, but might need to rename to .txt or .zip

No response

kofa73 commented 1 week ago

I'll try to look into the recursive SQL during the weekend. I haven't written one in decades :)