Description
openedon Sep 9, 2024
- Package Name: azure.search.documents
- Package Version: 11.6.0b4
- Operating System: OSX, version: 14.6.1
- Python Version: 3.9.6
Describe the bug
When attempting to use the azure-search-documents SDK, the encryption key provided is not accepted due to a type mismatch.
The SDK does not handle the type correctly, leading to a failure during deserialization when creating the data source connection. As according to the Microsoft documentation, SearchResourceEncryptionKey object is passed, but an error arises, where an iterable type is expected for encryption key.
Microsoft docs: https://learn.microsoft.com/en-us/python/api/azure-search-documents/azure.search.documents.indexes.models.searchindexerdatasourceconnection?view=azure-python
Python Library: https://pypi.org/project/azure-search-documents/11.5.0/
To Reproduce
Steps to reproduce the behaviour:
Assuming Blob Storage Account , AI Search, Index and indexer all already exists and managed identity enabled.
- Install the library azure-search-documents==11.6.0b4
- Define SearchResourceEncryptionKey object for encryption.
- Create Indexer client.
- Define data source connection passing SearchResourceEncryptionKey object defined earlier.
- Attempt to create a data source connection for ab indexer.
- Observe the "not iterable" error during the deserialization process.
from azure.search.documents.indexes import SearchIndexerClient
from azure.core.credentials import AzureKeyCredential
from azure.search.documents.indexes.models import SearchIndexerDataSourceConnection, SearchResourceEncryptionKey
# Initialize the client
indexer_client = SearchIndexerClient(endpoint="https://<your-search-service>.search.windows.net",
credential=AzureKeyCredential("<your-key>"))
# Define an encryption key
encryption_key = SearchResourceEncryptionKey(
key_name="your-key-name",
key_version="your-key-version",
vault_uri="https://<your-keyvault-name>.vault.azure.net/",
application_id="<your-client-app-id>",
application_secret="<your-server-app-secret>",
)
# Attempt to create a data source connection for an indexer
data_source_connection = SearchIndexerDataSourceConnection(
name="my-datasource",
type="azureblob",
connection_string=<your-blob-managed-identity-connection-string>,
container=SearchIndexerDataContainer(name=<your-container>, query=<your-folder-path>)
encryption_key=encryption_key # Pass SearchResourceEncryptionKey
)
try:
indexer_client.create_or_update_data_source_connection(data_source_connection)
except Exception as e:
print(f"Failed to create data source connection: {e}")
Expected behaviour
The SDK should correctly handle the SearchResourceEncryptionKey when creating a data source connection for an indexer.
Actual behaviour
The operation fails with a "not iterable" error, suggesting that the SDK is not properly handling the SearchResourceEncryptionKey object during deserialization.
Error Message I receive:
connector: <aiohttp.connector.TCPConnector object at 0x13f764340>
<class 'azure.search.documents.indexes.models._models.SearchResourceEncryptionKey'>
--- Logging error ---
Traceback (most recent call last):
File "/Users/redacted-project-path/.venv/lib/python3.9/site-packages/azure/search/documents/indexes/_generated/_serialization.py", line 1461, in _deserialize
found_value = key_extractor(attr, attr_desc, data)
File "/Users/redacted-project-path/.venv/lib/python3.9/site-packages/azure/search/documents/indexes/_generated/_serialization.py", line 1230, in rest_key_case_insensitive_extractor
return attribute_key_case_insensitive_extractor(key, None, working_data)
File "/Users/redacted-project-path/.venv/lib/python3.9/site-packages/azure/search/documents/indexes/_generated/_serialization.py", line 1257, in attribute_key_case_insensitive_extractor
for key in data:
TypeError: 'SearchResourceEncryptionKey' object is not iterable```