stashapp / stash

An organizer for your porn, written in Go. Documentation: https://docs.stashapp.cc
https://stashapp.cc/
GNU Affero General Public License v3.0
8.44k stars 749 forks source link

[Bug Report] Marker search error resulting from incorrect SQL query. #5013

Closed CosimoVestri closed 1 week ago

CosimoVestri commented 1 week ago

Describe the bug When using the search field on the Markers page, any input will result in an error due to a missing SQL JOIN to the scenes table.

To Reproduce Steps to reproduce the behavior:

  1. Go to Markers
  2. Click on the search field
  3. Enter anything
  4. See error:
    error executing count query with SQL: SELECT COUNT(*) as count FROM (SELECT DISTINCT scene_markers.id FROM scene_markers LEFT JOIN tags ON scene_markers.primary_tag_id = tags.id WHERE (scene_markers.title LIKE ? OR scenes.title LIKE ? OR tags.name LIKE ?)) as temp, args: [%text% %text% %text%], error: error executing `SELECT COUNT(*) as count FROM (SELECT DISTINCT scene_markers.id FROM scene_markers LEFT JOIN tags ON scene_markers.primary_tag_id = tags.id WHERE (scene_markers.title LIKE ? OR scenes.title LIKE ? OR tags.name LIKE ?)) as temp` [[%text% %text% %text%]]: no such column: scenes.title

    Expected behavior The correct SQL query would be:

    SELECT COUNT(*) AS count
    FROM 
    (SELECT DISTINCT scene_markers.id
    FROM scene_markers
    LEFT JOIN tags
      ON scene_markers.primary_tag_id = tags.id
    LEFT JOIN scenes
      ON scene_markers.scene_id = scenes.id
    WHERE (scene_markers.title LIKE '%text%'
          OR scenes.title LIKE '%text%'
          OR tags.name LIKE '%text%')) AS temp

    However the JOIN to the scenes table is missing which means this is the query being executed:

SELECT COUNT(*) AS count
FROM 
  (SELECT DISTINCT scene_markers.id
  FROM scene_markers
  LEFT JOIN tags
      ON scene_markers.primary_tag_id = tags.id
  WHERE (scene_markers.title LIKE '%text%'
          OR scenes.title LIKE '%text%'
          OR tags.name LIKE '%text%')) AS temp

So the scenes.title column would be missing.

Stash Version: (from Settings -> About): v0.26.1-24-ga8fca47a

Additional context @DogmaDragon confirmed the error.