This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 174874307b [python] Reject disabling query auth with dynamic options 
(#10908)
174874307b is described below

commit 174874307b1b3d9844591ecdc8ed19647189376b
Author: Jiajia Li <[email protected]>
AuthorDate: Sun Nov 1 22:47:58 2026 +0800

    [python] Reject disabling query auth with dynamic options (#10908)
---
 paimon-python/pypaimon/table/file_store_table.py   |  8 +++
 .../pypaimon/tests/native_cast_completion_test.py  |  3 +-
 .../pypaimon/tests/native_hybrid_search_test.py    |  6 +--
 .../pypaimon/tests/query_auth_filter_test.py       |  2 +-
 .../pypaimon/tests/ray_read_by_row_id_test.py      | 12 +++++
 .../pypaimon/tests/table_query_auth_test.py        | 59 ++++++++++++++++++++++
 6 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/paimon-python/pypaimon/table/file_store_table.py 
b/paimon-python/pypaimon/table/file_store_table.py
index 30111c91e9..18938bad5e 100644
--- a/paimon-python/pypaimon/table/file_store_table.py
+++ b/paimon-python/pypaimon/table/file_store_table.py
@@ -506,6 +506,14 @@ class FileStoreTable(Table):
         return table
 
     def _copy(self, options: dict, resolve_time_travel: bool) -> 
'FileStoreTable':
+        query_auth_key = CoreOptions.QUERY_AUTH_ENABLED.key()
+        if query_auth_key in options and 
CoreOptions.from_dict(self.table_schema.options).query_auth_enabled:
+            try:
+                enabled = CoreOptions.from_dict(options).query_auth_enabled
+            except ValueError:
+                enabled = False
+            if not enabled:
+                raise ValueError(f"Option '{query_auth_key}' is not allowed to 
be disabled dynamically")
         video_key = CoreOptions.VIDEO_FRAME_FIELD.key()
         if video_key in options and options[video_key] != 
self.table_schema.options.get(video_key):
             raise ValueError("Cannot change immutable option " + video_key)
diff --git a/paimon-python/pypaimon/tests/native_cast_completion_test.py 
b/paimon-python/pypaimon/tests/native_cast_completion_test.py
index bcbe4042ea..445f6a1141 100644
--- a/paimon-python/pypaimon/tests/native_cast_completion_test.py
+++ b/paimon-python/pypaimon/tests/native_cast_completion_test.py
@@ -213,8 +213,7 @@ def 
test_not_null_mask_adapts_only_output_schema(rest_catalog, table_mode, mask)
     if mask == 'null':
         # Captured rules must still determine output nullability on the 
existing
         # fallback reader; no additional Python CAST implementation is needed.
-        fallback = table.copy({'query-auth.enabled': 'false', 
'read.native.enabled': 'false',
-                               'scan.native-plan.enabled': 'false'})
+        fallback = table.copy({'read.native.enabled': 'false', 
'scan.native-plan.enabled': 'false'})
         captured = fallback.new_read_builder().with_projection(['masked', 
'id'])
         with captured.new_read().to_arrow_batch_reader(splits) as batches:
             batch = batches.read_next_batch()
diff --git a/paimon-python/pypaimon/tests/native_hybrid_search_test.py 
b/paimon-python/pypaimon/tests/native_hybrid_search_test.py
index 37f907c8a5..ef7a980437 100644
--- a/paimon-python/pypaimon/tests/native_hybrid_search_test.py
+++ b/paimon-python/pypaimon/tests/native_hybrid_search_test.py
@@ -475,10 +475,10 @@ def 
test_unsupported_literal_qualifies_before_core_execution(rest_catalog):
 @pytest.mark.parametrize('native', [False, True])
 def test_query_auth_rejects_hybrid_before_native_table_access(rest_catalog, 
native):
     catalog, _ = rest_catalog
-    table = _table(catalog)
-    table = table.copy({'query-auth.enabled': 'true', 'read.native.enabled': 
str(native).lower()})
+    raw_table = _table(catalog)
+    table = raw_table.copy({'query-auth.enabled': 'true', 
'read.native.enabled': str(native).lower()})
     with 
patch('pypaimon.execution.native.read.native_hybrid_search._native_table',
                side_effect=AssertionError('Native table access before 
authorization')):
         with pytest.raises(Exception, match='query-auth'):
             _builder(table).execute_local()
-    assert indexes._ids(table.copy({'query-auth.enabled': 'false'})) == 
list(range(8))
+    assert indexes._ids(raw_table) == list(range(8))
diff --git a/paimon-python/pypaimon/tests/query_auth_filter_test.py 
b/paimon-python/pypaimon/tests/query_auth_filter_test.py
index e24d5eb482..92559342ab 100644
--- a/paimon-python/pypaimon/tests/query_auth_filter_test.py
+++ b/paimon-python/pypaimon/tests/query_auth_filter_test.py
@@ -483,7 +483,7 @@ def 
test_post_mask_string_filter_uses_declared_type(tmp_path, condition, pattern
 
 @pytest.mark.parametrize('table', ['primary-key', 'partitioned-primary-key'], 
indirect=True)
 def test_streaming_post_mask_filter_keeps_delete_row_kind(table):
-    builder = table.copy({'query-auth.enabled': 
'false'}).new_batch_write_builder()
+    builder = table.new_batch_write_builder()
     writer = builder.new_write()
     try:
         writer.write_row(GenericRow([2, 'beta', 'visible'], table.fields, 
RowKind.DELETE))
diff --git a/paimon-python/pypaimon/tests/ray_read_by_row_id_test.py 
b/paimon-python/pypaimon/tests/ray_read_by_row_id_test.py
index 1627acc0c5..c11d5503b3 100644
--- a/paimon-python/pypaimon/tests/ray_read_by_row_id_test.py
+++ b/paimon-python/pypaimon/tests/ray_read_by_row_id_test.py
@@ -203,6 +203,18 @@ class RayReadByRowIdTest(unittest.TestCase):
             read_by_row_id(target, src, self.catalog_options, 
projection=["age"],
                            dynamic_options={"deletion-vectors.enabled": 
"true"})
 
+    def test_rejects_disabling_query_auth_dynamically(self):
+        target = self._create({**self.de_options, "query-auth.enabled": 
"true"})
+        self._write(target, pa.Table.from_pydict(
+            {"id": [1], "name": ["a"], "age": [1]}, schema=self.pa_schema))
+        src = pa.table({"_ROW_ID": [0]}, schema=pa.schema([("_ROW_ID", 
pa.int64())]))
+        for value in ("false", False, None, "invalid"):
+            with self.subTest(value=value):
+                with self.assertRaisesRegex(
+                        ValueError, "^Option 'query-auth.enabled' is not 
allowed to be disabled dynamically$"):
+                    read_by_row_id(target, src, self.catalog_options, 
projection=["age"],
+                                   dynamic_options={"query-auth.enabled": 
value})
+
     def test_time_travel_via_dynamic_options(self):
         target = self._create()
         self._write(target, pa.Table.from_pydict(
diff --git a/paimon-python/pypaimon/tests/table_query_auth_test.py 
b/paimon-python/pypaimon/tests/table_query_auth_test.py
index a320343050..c3ab075ebc 100644
--- a/paimon-python/pypaimon/tests/table_query_auth_test.py
+++ b/paimon-python/pypaimon/tests/table_query_auth_test.py
@@ -21,9 +21,12 @@ import unittest
 from unittest.mock import patch
 
 import pyarrow as pa
+import pytest
 
 from types import SimpleNamespace
 
+from pypaimon import Schema
+from pypaimon.api.api_response import AuthTableQueryResponse
 from pypaimon.catalog.catalog_exception import TableNoPermissionException
 from pypaimon.catalog.table_query_auth import (
     TableQueryAuthResult,
@@ -35,6 +38,10 @@ from pypaimon.read.plan import Plan
 from pypaimon.read.query_auth_split import QueryAuthSplit
 from pypaimon.read.scan_stats import ScanStats
 from pypaimon.read.table_scan import TableScan
+from pypaimon.tests import native_plan_rest_test
+
+
+rest_catalog = native_plan_rest_test.rest_catalog
 
 
 class _FakeField:
@@ -482,6 +489,58 @@ class TestCoreOptionsQueryAuth(unittest.TestCase):
         self.assertFalse(opts.query_auth_enabled)
 
 
[email protected]("copy_method", ["copy", "copy_without_time_travel"])
[email protected]("enabled", ["true", True, "on"])
+def test_query_auth_cannot_be_disabled_dynamically(rest_catalog, copy_method, 
enabled):
+    catalog, server = rest_catalog
+    schema = pa.schema([("dept", pa.string()), ("secret", pa.string())])
+    catalog.create_table("default.auth", Schema.from_pyarrow_schema(
+        schema, options={"query-auth.enabled": enabled}), False)
+    table = catalog.get_table("default.auth")
+    builder = table.new_batch_write_builder()
+    writer = builder.new_write()
+    commit = builder.new_commit()
+    try:
+        writer.write_arrow(pa.Table.from_pydict({
+            "dept": ["eng", "other"], "secret": ["secret1", "secret2"],
+        }, schema=schema))
+        commit.commit(writer.prepare_commit())
+    finally:
+        writer.close()
+        commit.close()
+    server.table_query_auth_store[table.identifier.get_full_name()] = 
AuthTableQueryResponse(
+        filter=[_simple_filter_json()], column_masking={"secret": 
'{"name":"NULL"}'})
+
+    copy = getattr(table, copy_method)
+    for value in ("false", "FaLsE", False, None, "", "invalid", "0", 0, "off", 
"no"):
+        with pytest.raises(ValueError) as error:
+            copy({"query-auth.enabled": value})
+        assert str(error.value) == "Option 'query-auth.enabled' is not allowed 
to be disabled dynamically"
+
+    for options in [{}] + [{"query-auth.enabled": value} for value in ("true", 
"TrUe", True, " on ", 1)]:
+        copied = copy(options)
+        read = copied.new_read_builder()
+        result = read.new_read().to_arrow(read.new_scan().plan().splits())
+        assert result.to_pydict() == {"dept": ["eng"], "secret": [None]}
+        with pytest.raises(ValueError, match="Search is not supported on a 
query-auth table"):
+            copied.new_vector_search_builder().new_vector_search_scan()
+    assert table.table_schema.options["query-auth.enabled"] == enabled
+
+
[email protected]("copy_method", ["copy", "copy_without_time_travel"])
[email protected]("options", [{}, {"query-auth.enabled": "false"}])
+def test_query_auth_can_be_enabled_dynamically(rest_catalog, copy_method, 
options):
+    catalog, _ = rest_catalog
+    catalog.create_table("default.plain", Schema.from_pyarrow_schema(
+        pa.schema([("secret", pa.string())]), options=options), False)
+    table = catalog.get_table("default.plain")
+    for value, enabled in (("false", False), (False, False), (None, False),
+                           ("true", True), ("TrUe", True), (True, True), 
("on", True)):
+        copied = getattr(table, copy_method)({"query-auth.enabled": value})
+        assert copied.options.query_auth_enabled == enabled
+    assert not table.options.query_auth_enabled
+
+
 if __name__ == "__main__":
     unittest.main()
 

Reply via email to