Skip to content

fix(python): raise clear TypeError for bare List/Tuple in pydantic schema conversion#3511

Merged
wjones127 merged 1 commit into
lancedb:mainfrom
Ar-maan05:fix/pydantic-bare-generic-3502
Jun 17, 2026
Merged

fix(python): raise clear TypeError for bare List/Tuple in pydantic schema conversion#3511
wjones127 merged 1 commit into
lancedb:mainfrom
Ar-maan05:fix/pydantic-bare-generic-3502

Conversation

@Ar-maan05

Copy link
Copy Markdown
Contributor

Closes #3502

Problem

A bare, unparameterised typing.List / typing.Tuple field crashes to_arrow_schema with an opaque AttributeError: __args__:

from typing import Tuple
from lancedb.pydantic import LanceModel

class Doc(LanceModel):
    items: Tuple

Doc.to_arrow_schema()  # AttributeError: __args__

In _py_type_to_arrow_type, the branch elif getattr(py_type, "__origin__", None) in (list, tuple) is taken for a bare generic (its __origin__ is list / tuple), but the next line reads py_type.__args__[0], and a bare generic has no __args__. Other unsupported types (e.g. Dict[str, int]) correctly raise a clear TypeError, so this case is inconsistent.

Fix

Guard the element-type lookup with getattr(py_type, "__args__", None) and raise a clear TypeError when it is missing, matching the existing behavior for other unsupported types. Bare builtin list / tuple are unaffected (their __origin__ is None, so they already fall through to the existing TypeError).

Testing

  • Added test_bare_generic_raises_type_error covering both List and Tuple.
  • ruff format and ruff check clean.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added bug Something isn't working Python Python SDK labels Jun 6, 2026
@Ar-maan05

Copy link
Copy Markdown
Contributor Author

Friendly ping! Let me know if any changes are needed.

@Ar-maan05

Copy link
Copy Markdown
Contributor Author

Hi, friendly ping, please let me know if any changes are needed.

@wjones127
wjones127 merged commit b2ae763 into lancedb:main Jun 17, 2026
12 checks passed
@Ar-maan05
Ar-maan05 deleted the fix/pydantic-bare-generic-3502 branch June 19, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Python Python SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bare typing.Tuple/List field crashes to_arrow_schema with AttributeError: __args__

2 participants