stashapp / CommunityScripts

This is a public repository containing plugin and utility scripts created by the Stash Community.
https://docs.stashapp.cc/add-ons/
GNU Affero General Public License v3.0
190 stars 147 forks source link

🐞find_duplicate_scenes throws exception #401

Closed David-Maisonave closed 3 months ago

David-Maisonave commented 3 months ago

Calling find_duplicate_scenes with no arguments throws an exception.

Logging

Error   [Plugin / FileMonitor] Exception: StashAPI error: fragment "SceneSlim" not defined
Error   [Plugin / FileMonitor]     raise Exception(f'StashAPI error: fragment "{fragment}" not defined')
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 58, in __resolve_fragments
Error   [Plugin / FileMonitor]     query = self.__resolve_fragments(query)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 217, in _GQL
Error   [Plugin / FileMonitor]     return self._GQL(query, variables)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\stashapp.py", line 219, in call_GQL
Error   [Plugin / FileMonitor]     result = self.call_GQL(query, variables)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\stashapp.py", line 1830, in find_duplicate_scenes
Error   [Plugin / FileMonitor]     stash.Log(f"{stash.find_duplicate_scenes()}")
Error   [Plugin / FileMonitor]   File "C:\Users\admin3\.stash\plugins\FileMonitor\filemonitor.py", line 48, in <module>

Setup Details

stashapp-tools version: 0.2.50 OS: Windows 11

Code to reproduce issue:

stash.log.debug(f"{stash.find_duplicate_scenes()}")

Playground GraphiQL shows the following arguments:

find_duplicate_scenes_GraphiQL

It doesn't list SceneSlim as an argument. It does show duration_diff argument which is not present in find_duplicate_scenes.

I modified the code to the following:

    def find_duplicate_scenes(self, distance: PhashDistance=PhashDistance.EXACT, fragment=None):
        query = """
            query FindDuplicateScenes($distance: Int) {
                findDuplicateScenes(distance: $distance) {
                    ...SceneSlim
                }
            }
        """
        if fragment:
            query = re.sub(r'\.\.\.SceneSlim', fragment, query)
        else:
            query = """
                query FindDuplicateScenes($distance: Int) {
                    findDuplicateScenes(distance: $distance)
                }
            """    
        variables = { 
            "distance": distance
        }
        result = self.call_GQL(query, variables)
        return result['findDuplicateScenes']

But that still threw the following exception:

Error   [Plugin / FileMonitor] Exception: 422 Unprocessable Entity query failed. v0.26.2-2
Error   [Plugin / FileMonitor]     raise Exception(error_msg)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 270, in _handle_GQL_response
Error   [Plugin / FileMonitor]     return self._handle_GQL_response(response)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 227, in _GQL
Error   [Plugin / FileMonitor]     return self._GQL(query, variables)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\stashapp.py", line 219, in call_GQL
Error   [Plugin / FileMonitor]     result = self.call_GQL(query, variables)
Error   [Plugin / FileMonitor]   File "C:\Users\admin3\.stash\plugins\FileMonitor\StashPluginHelper.py", line 344, in find_duplicate_scenes
Error   [Plugin / FileMonitor]     stash.log.debug(f"{stash.find_duplicate_scenes()}")
Error   [Plugin / FileMonitor]   File "C:\Users\admin3\.stash\plugins\FileMonitor\filemonitor.py", line 48, in <module>
Error   [Plugin / FileMonitor] Traceback (most recent call last):
Error   [Plugin / FileMonitor] d
Error   [Plugin / FileMonitor] 422 Unprocessable Entity query failed. v0.26.2-2
Error   [Plugin / FileMonitor] 422 Unprocessable Entity GQL data response is null
Error   [Plugin / FileMonitor] GRAPHQL_VALIDATION_FAILED: Field "findDuplicateScenes" of type "[[Scene!]!]!" must have a selection of subfields. Did you mean "findDuplicateScenes { ... }"?

The last thing I tried was calling it with fragment argument, but that threw the following exception:

Error   [Plugin / FileMonitor] Exception: 422 Unprocessable Entity query failed. v0.26.2-2
Error   [Plugin / FileMonitor]     raise Exception(error_msg)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 270, in _handle_GQL_response
Error   [Plugin / FileMonitor]     return self._handle_GQL_response(response)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\classes.py", line 227, in _GQL
Error   [Plugin / FileMonitor]     return self._GQL(query, variables)
Error   [Plugin / FileMonitor]   File "C:\Users\david\AppData\Local\Programs\Python\Python310\lib\site-packages\stashapi\stashapp.py", line 219, in call_GQL
Error   [Plugin / FileMonitor]     result = self.call_GQL(query, variables)
Error   [Plugin / FileMonitor]   File "C:\Users\admin3\.stash\plugins\FileMonitor\StashPluginHelper.py", line 344, in find_duplicate_scenes
Error   [Plugin / FileMonitor]     stash.log.debug(f"{stash.find_duplicate_scenes(stash.FRAGMENT_SERVER)}")
Error   [Plugin / FileMonitor]   File "C:\Users\admin3\.stash\plugins\FileMonitor\filemonitor.py", line 48, in <module>
Error   [Plugin / FileMonitor] Traceback (most recent call last):
Error   [Plugin / FileMonitor] d
Error   [Plugin / FileMonitor] 422 Unprocessable Entity query failed. v0.26.2-2
Error   [Plugin / FileMonitor] 422 Unprocessable Entity GQL data response is null
Error   [Plugin / FileMonitor] GRAPHQL_VALIDATION_FAILED: Field "findDuplicateScenes" of type "[[Scene!]!]!" must have a selection of subfields. Did you mean "findDuplicateScenes { ... }"?
stg-annon commented 3 months ago

SceneSlim is an undefined fragment it is an issue with the stashapi library as it used to be defined but has since been removed, if you define a fragment it will work, the reason it does not use the full Scene fragment is that it would take much longer to run

the whole point of GQL is so that you can define the shape of the object you want to get back from the API, stashapi kind of defeats the purpose of that by automatically providing full fragments for all the objects

it was patched with https://github.com/stg-annon/stashapi/commit/0b08bbed5ec984544a4dc0444f456e6068ec4ad6

David-Maisonave commented 3 months ago

Thanks