1

I am using Azurite 3.33.0 to emulate Azure Blob Storage locally, and I am trying to query blobs by multiple tags using the find_blobs_by_tags method. This should recently have been fixed by Azurite (https://github.com/Azure/Azurite/issues/647). However, I am encountering issues when attempting to query blobs with multiple conditions for a single tag. Specifically, the query fails with an HttpResponseError (Internal Server Error) when I try to filter using multiple conditions.

The following query works fine for filtering by a single tag:

blob_service_client = BlobServiceClient(
    account_url=azure_blob_storage_endpoint, credential=credentials
)

container_client = blob_service_client.get_container_client(
    container=container_name
)

start_year = 2012
end_year = 2022

query = f"\"year\">='{start_year}'"
next(container_client.find_blobs_by_tags(filter_expression=query))["name"]

However, it fails when I attempt to apply two conditions on a single tag to define a range like this:

query = (
    f"\"year\">='{start_year}' AND \"year\"<='{end_year}'"
)
next(container_client.find_blobs_by_tags(filter_expression=query))["name"]

I get the following error: azure.core.exceptions.HttpResponseError: Internal Server Error ErrorCode: None The debugs show the following error:

info: HandlerMiddleware: DeserializedParameters={"options":{"where":"\"year\">='2012' AND \"year\"<='2022'","include":[],"requestId":"65c52b18-d417-11ef-84c3-c84bd64ac0da"},"restype":"container","comp":"blobs","version":"2025-01-05"}
error: ErrorMiddleware: ErrorName=Error ErrorMessage=can't have multiple conditions for a single tag unless they define a range ErrorStack="Error: can't have multiple conditions for a single tag unless they define a range\n    at QueryParser.validateWithPreviousComparison (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:81:27)\n    at QueryParser.visitBinary (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:249:26)\n    at QueryParser.visitExpressionGroup (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:208:25)\n    at QueryParser.visitUnary (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:189:28)\n    at QueryParser.visitAnd (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:170:27)\n    at QueryParser.visitAnd (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:173:32)\n    at QueryParser.visitOr (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:149:27)\n    at QueryParser.visitExpression (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:139:21)\n    at QueryParser.visitQuery (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:126:27)\n    at QueryParser.visit (/opt/azurite/dist/src/blob/persistence/QueryInterpreter/QueryParser.js:118:21)"

My code does work when I am querying on the actual Azure Blob Storage, just in my azurite blob storage it fails.

Questions:

  • Is querying multiple conditions on a single blob tag not supported in Azurite 3.33.0?
  • Are there any known issues or limitations with find_blobs_by_tags in Azurite 3.33.0 that could explain this behavior?
2
  • Try updating to the latest version of Azurite. Commented Jan 15 at 12:55
  • I am currently on the latest version of Azurite, v3.33.0. Commented Jan 16 at 10:58

1 Answer 1

0

I successfully queried blobs with multiple tags combined using the AND operator in Azurite locally. Below is the modified code.

blob_query.py :

from azure.storage.blob import BlobServiceClient

account_url = "http://127.0.0.1:10000/devstoreaccount1"  
credentials = '<key>'  
blob_service_client = BlobServiceClient(account_url=account_url, credential=credentials)

container_name = 'test'
container_client = blob_service_client.get_container_client(container=container_name)

def query_blobs_by_multiple_tags(query):
    blobs = []
    try:
        results = container_client.find_blobs_by_tags(filter_expression=query)
        for blob in results:
            blobs.append(blob['name'])
    except Exception as e:
        print(f"Error querying blobs: {e}")
    return blobs

tag = 'tagValue1' 
year_month = '2020-09'     

query = f"\"tag\"='{tag}'"
blobs_by_tags = query_blobs_by_multiple_tags(query)
print(f"Blobs with tag '{tag}': {blobs_by_tags}")

query = f"\"tag\"='{tag}' AND \"year_month\">='{year_month}'"
blobs_by_tags_and_year = query_blobs_by_multiple_tags(query)
print(f"Blobs with tag '{tag}' and year-month greater than or equal to '{year_month}': {blobs_by_tags_and_year}")

Output :

I successfully got the output for the query.

enter image description here

I ran the below command to confirm that Azurite is running on port 10000 for the Blob service.

azurite --location ./azurite_data --debug ./azurite_debug.log

enter image description here

Reference :

You can check the @Jim Xu answer to create a container and upload blobs to Azurite.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, this helped me to get a better idea of were the problem is. However it seems that the problem is not related to multiple tags, but specifically doing greater than/smaller than queries on the same tag. In my instance, I am using tags like 2020-09 to determine the month and year the data describes. And I want to filter on a specific period. However, this seems to cause an error, which is not normally caused by the actual blob storage.
I have updated the answer to use tags like '2020-09' to determine the month and year the data describes.
The exact query I would need is f"\"year_month\">='{year_month}'' AND \"year_month\"<='{year_month2}'", but that results in this error message -> Error: can't have multiple conditions for a single tag unless they define a range
I will try and update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.