Skip to content

Error with ParalleQuery with response_handler when queries have more than 1 command #181

Closed

Description

@luisremis

Here is one example where it failed.

from aperturedb.ParallelQuery import ParallelQuery
from aperturedb.QueryGenerator import QueryGenerator

import random

class UpdateAndCheckImageLabel(QueryGenerator):

    def __init__(self, imgids, field, new_labels, changed_ids):
        
        self.field = field
        self.imgids = imgids
        self.new_labels = new_labels
        self.changed_ids = changed_ids

    def __len__(self):

        return len(self.imgids)

    def getitem(self, idx):

        id = self.imgids[idx]
        label = self.new_labels[idx]

        q = [{
            "FindImage": {
                "blobs": False,
                "constraints": {
                    "image_id": [ "==", id ],
                    field: ["!=", label]
                },
                "results": {
                    "count": True,
                    "list": ["image_id"]
                }
            }
         }, {
             "UpdateImage": ...
         }]

        return q, []
    
    def response_handler(self, q, b ,r, r_b ):

        try:
            count  = r[0]["FindImage"]["count"]

            if count == 1:
                img_id = r[0]["FindImage"]["entities"][0]["image_id"]
                self.changed_ids.append(img_id)

        except Exception as e:
            print(f"Response Handler Error: {r}")
            print(f"Exception: {e}")
            
changed_id = []
new_imgids = imgids[0:1000]
field = "image_type"
new_labels = ["Silo" for i in imgids]

generator = UpdateAndCheckImageLabel(new_imgids, field, new_labels, changed_id)
querier = ParallelQuery(db)
querier.run(generator, numthreads=32, batchsize=100, stats=True)

print(len(changed_id))
print(changed_id)

Activity

  1. added
    bug
    on Dec 15, 2022
  2. self-assigned this
    on May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions