airbytehq / PyAirbyte

PyAirbyte brings the power of Airbyte to every Python developer.
https://docs.airbyte.com/pyairbyte
Other
176 stars 20 forks source link

source-zendesk-support: TypeError: unhashable type: 'list' #244

Closed nakamichiworks closed 1 month ago

nakamichiworks commented 1 month ago

I got the following error when I ran source-zendesk-support connector.

import os

import airbyte as ab

source = ab.get_source(
    "source-zendesk-support",
    config={
        "subdomain": os.getenv("ZENDESK_API_SUBDOMAIN"),
        "start_date": "2024-05-17T00:00:00Z",
        "credentials": {
            "credentials": "api_token",
            "email": os.getenv("ZENDESK_API_EMAIL"),
            "api_token": os.getenv("ZENDESK_API_TOKEN"),
        },
    },
)
source.check()
source.select_streams(["tickets"])
result = source.read()
Traceback (most recent call last):
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/sources/base.py", line 734, in read
    cache_processor.process_airbyte_messages(
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/_future_cdk/record_processor.py", line 217, in process_airbyte_messages
    self.write_all_stream_data(
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/_future_cdk/record_processor.py", line 226, in write_all_stream_data
    self.write_stream_data(
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/_future_cdk/sql_processor.py", line 508, in write_stream_data
    final_table_name = self._ensure_final_table_exists(
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/_future_cdk/sql_processor.py", line 402, in _ensure_final_table_exists
    for column_name, sql_type in self._get_sql_column_definitions(
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/_future_cdk/sql_processor.py", line 476, in _get_sql_column_definitions
    columns[clean_prop_name] = self.type_converter.to_sql_type(
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/types.py", line 123, in to_sql_type
    airbyte_type, _ = _get_airbyte_type(json_schema_property_def)
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/types.py", line 67, in _get_airbyte_type
    if json_schema_type in {"string", "number", "boolean", "integer"}:
TypeError: unhashable type: 'list'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/private/tmp/test-pyairbyte/load_zendesk_support_data.py", line 19, in <module>
    result = source.read()
  File "/private/tmp/test-pyairbyte/.venv/lib/python3.9/site-packages/airbyte/sources/base.py", line 745, in read
    raise exc.AirbyteConnectorFailedError(
airbyte.exceptions.AirbyteConnectorFailedError: AirbyteConnectorFailedError: Connector failed.

After debugging, I found that this JSON schema type is not properly handled by _get_airbyte_type() function, which means json_schema_type = ["null", "object", "string"] causes TypeError: unhashable type: 'list'.

Can I fix this, or do you have any workaround?


Package versions:

aaronsteers commented 1 month ago

@nakamichiworks - Thanks for reporting this. I can see and confirm this is an issue. The "in" check should first check if the object is a string, so as to avoid the "unhashable" error. We can also add this scenario to our unit tests. I'm considering also wrapping most/all of the logic in a try block so that unexpected inputs can still have a safe failover type (str or json).

aaronsteers commented 1 month ago

@nakamichiworks - This should be resolved by:

Which just merged.

Can you retry using PyAirbyte 0.11.1 (released just now) and let us know if this resolves your issue? Thanks!