Skip to content

fix: resolve flaky tenant input validation in Python 3.12#2043

Open
paulxg12 wants to merge 1 commit into
weaviate:mainfrom
paulxg12:fix/flaky-tenant-validation-python312
Open

fix: resolve flaky tenant input validation in Python 3.12#2043
paulxg12 wants to merge 1 commit into
weaviate:mainfrom
paulxg12:fix/flaky-tenant-validation-python312

Conversation

@paulxg12
Copy link
Copy Markdown

What

Replaces typing.Sequence with collections.abc.Sequence for all runtime isinstance/issubclass checks in the input validator. The existing tests pass in Python 3.9-3.14 after this change.

Why

Fixes #1355. In Python 3.12+, typing.Sequence can produce flaky results when used in runtime isinstance() checks due to internal changes in the typing module. This causes valid Sequence[Union[Tenant, TenantUpdate]] inputs (e.g., a plain Python list of Tenant objects) to be incorrectly rejected with:

WeaviateInvalidInputError: Argument 'tenants' must be one of:
[Tenant, TenantUpdate, typing.Sequence[typing.Union[Tenant, TenantUpdate]]],
but got <class 'list'>.

How

  • Import Sequence from collections.abc (aliased as ABCSequence) — the canonical ABC for runtime type checking
  • Use ABCSequence for issubclass(expected_origin, ABCSequence) instead of issubclass(expected_origin, Sequence) (where Sequence was from typing)
  • Use isinstance(value, (ABCSequence, list)) as a simpler, more robust check
  • typing.Sequence is retained in the import since it's still used in type annotations

Testing

  • All 18 existing + new validator tests pass on Python 3.14.3
  • New test cases cover the Sequence[Union[str, int]] pattern that reproduces the same code path as the reported failure
  • The fix is expected to work across Python 3.9 through 3.14

Checklist

  • Follows existing code style
  • Tests pass locally
  • No breaking changes
  • Documentation updated if needed

Use  instead of  for runtime
issubclass/isinstance checks in the input validator. The typing module's
Sequence can produce flaky isinstance() results in Python 3.12+ due to
internal changes in the typing module, causing valid Sequence inputs
(e.g., a list of Tenant objects) to be incorrectly rejected.

Also adds targeted test coverage for the Sequence[Union[...]] validation
pattern that reproduces the reported failure scenario.
Copy link
Copy Markdown

@orca-security-eu orca-security-eu Bot left a comment

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot
Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix flaky tenant input validations in different Python versions

3 participants