Skip to content

feat(pyamber): require bucket and key in large binary URIs - #9626

Draft
Matthew-DWM wants to merge 1 commit into
apache:mainfrom
Matthew-DWM:feat/large-binary-uri-key
Draft

Matthew-DWM wants to merge 1 commit into
apache:mainfrom
Matthew-DWM:feat/large-binary-uri-key

Conversation

@Matthew-DWM

Copy link
Copy Markdown

What changes were proposed in this PR?

largebinary only checked the s3:// prefix, so s3://, s3:///object, s3://bucket and s3://bucket/ were accepted and failed later, when a stream called S3 with an empty bucket or object key. The constructor now parses the URI with urlparse, as get_bucket_name() and get_object_key() already do, and raises ValueError naming the URI when either part is empty. Mirroring the getters also rejects s3://bucket// and s3://bucket/?versionId=1, which a simple regex would accept.

Before:  largebinary("s3://bucket") -> accepted, key ""  -> fails later inside S3
After:   largebinary("s3://bucket") -> ValueError: largebinary URI must include a bucket and object key, got: s3://bucket

Behavior changes:

  • largebinary() with a misconfigured base URI (e.g. s3://) now fails on creation instead of on upload.
  • The JVM LargeBinary still checks only the prefix. A keyless URI built there now fails in the next Python operator, even one that only passes the tuple on, instead of later in S3. JVM parity is a follow-up.

Any related issues, documentation, discussions?

Closes #8279. Builds on #8280 by @carloea2, which proposed the same urlparse check; this adds the URI to the message, updates the docstring and widens the tests.

Follow-up for the JVM side: #9625

How was this PR tested?

New parametrized tests in test_large_binary.py cover six incomplete URIs (including both regex traps above), accepted URIs with edge-case keys (trailing slash, unicode), and largebinary() with a misconfigured base URI. The new tests were written before the fix and all pass with it; 8 of them fail on main with DID NOT RAISE.

From amber, with Python 3.12, after running bash bin/python-proto-gen.sh from the repo root:

python -m pytest src/test/python/core/models/type/test_large_binary.py -q
19 passed

python -m pytest src/test/python -m "not integration" -q
1525 passed, 3 failed, 59 deselected, 1 xfailed

ruff check src/main/python src/test/python
ruff format --check src/main/python src/test/python

The 3 failures are test_python_ui_parameter_value_contract[timestamp-*], which fail the same way on unmodified main here because the machine is not on UTC. Ruff lint and formatting pass, and the URI check behaves identically on Python 3.13.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)

largebinary.__init__ only checked the "s3://" prefix, so URIs such as
s3://, s3:///object, s3://bucket and s3://bucket/ constructed fine and
then reached S3 with an empty bucket or object key. The constructor now
parses the URI with urlparse, as get_bucket_name() and get_object_key()
already do, and raises ValueError naming the URI when either part is
empty, so every accepted URI yields a non-empty bucket and key.

The no-argument constructor goes through the same check, so a
misconfigured large-binaries base URI (for example "s3://") now fails
when the largebinary is created instead of at upload time.

Builds on the urlparse approach from apache#8280.
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @kunwp1
    You can notify them by mentioning @kunwp1 in a comment.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Large binary accepts incomplete S3 references

1 participant