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 2e61ff828d [python] Reject operations on the system database (#10841)
2e61ff828d is described below

commit 2e61ff828d22e34d50abdfeed7fbe1668de162a6
Author: Jiajia Li <[email protected]>
AuthorDate: Wed Oct 28 20:01:05 2026 +0800

    [python] Reject operations on the system database (#10841)
---
 paimon-python/pypaimon/catalog/catalog_utils.py     |  9 ++++++++-
 .../pypaimon/catalog/filesystem_catalog.py          |  4 +++-
 paimon-python/pypaimon/catalog/jdbc_catalog.py      |  4 ++++
 paimon-python/pypaimon/catalog/rest/rest_catalog.py |  5 ++++-
 .../pypaimon/tests/catalog_table_guard_test.py      | 21 +++++++++++++++++++++
 5 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/paimon-python/pypaimon/catalog/catalog_utils.py 
b/paimon-python/pypaimon/catalog/catalog_utils.py
index 492d60da9d..8deb937c1c 100644
--- a/paimon-python/pypaimon/catalog/catalog_utils.py
+++ b/paimon-python/pypaimon/catalog/catalog_utils.py
@@ -21,6 +21,7 @@ import re
 from typing import Optional
 
 from pypaimon.api.api_response import PagedList, Partition
+from pypaimon.catalog.catalog import Catalog
 from pypaimon.common.identifier import Identifier
 from pypaimon.table.table import Table
 
@@ -49,9 +50,15 @@ def check_not_branch(identifier: Identifier, method: str) -> 
None:
             .format(method, identifier.get_full_name()))
 
 
+def check_not_system_database(name: str) -> None:
+    """Mirrors Java ``CatalogUtils.checkNotSystemDatabase``."""
+    if name == Catalog.SYSTEM_DATABASE_NAME:
+        raise ValueError("Can't do operation on system database.")
+
+
 def check_not_system_table(identifier: Identifier, method: str) -> None:
     """Mirrors Java ``CatalogUtils.checkNotSystemTable``."""
-    if identifier.is_system_table():
+    if identifier.get_database_name() == Catalog.SYSTEM_DATABASE_NAME or 
identifier.is_system_table():
         raise ValueError(
             "Cannot '{}' for system table '{}', please use data table."
             .format(method, identifier.get_full_name()))
diff --git a/paimon-python/pypaimon/catalog/filesystem_catalog.py 
b/paimon-python/pypaimon/catalog/filesystem_catalog.py
index 76218a8bf8..f33211cbf9 100644
--- a/paimon-python/pypaimon/catalog/filesystem_catalog.py
+++ b/paimon-python/pypaimon/catalog/filesystem_catalog.py
@@ -21,7 +21,7 @@ from pypaimon.api.api_response import GetTagResponse, 
PagedList, Partition
 from pypaimon.catalog.catalog import Catalog
 from pypaimon.catalog.catalog_context import CatalogContext
 from pypaimon.catalog.catalog_environment import CatalogEnvironment
-from pypaimon.catalog.catalog_utils import check_not_branch, 
check_not_system_table
+from pypaimon.catalog.catalog_utils import check_not_branch, 
check_not_system_database, check_not_system_table
 from pypaimon.catalog.catalog_exception import (BranchAlreadyExistException,
                                                 BranchNotExistException,
                                                 DatabaseAlreadyExistException,
@@ -87,6 +87,7 @@ class FileSystemCatalog(Catalog):
 
     def create_database(self, name: str, ignore_if_exists: bool,
                         properties: Optional[Dict[str, str]] = None) -> None:
+        check_not_system_database(name)
         try:
             self.get_database(name)
             if not ignore_if_exists:
@@ -98,6 +99,7 @@ class FileSystemCatalog(Catalog):
             self.file_io.mkdirs(path)
 
     def drop_database(self, name: str, ignore_if_not_exists: bool = False, 
cascade: bool = False) -> None:
+        check_not_system_database(name)
         try:
             self.get_database(name)
         except DatabaseNotExistException:
diff --git a/paimon-python/pypaimon/catalog/jdbc_catalog.py 
b/paimon-python/pypaimon/catalog/jdbc_catalog.py
index 770a9c5f24..6ada44de64 100644
--- a/paimon-python/pypaimon/catalog/jdbc_catalog.py
+++ b/paimon-python/pypaimon/catalog/jdbc_catalog.py
@@ -26,6 +26,7 @@ from pypaimon.catalog.catalog_context import CatalogContext
 from pypaimon.catalog.catalog_environment import CatalogEnvironment
 from pypaimon.catalog.catalog_utils import (
     check_not_branch,
+    check_not_system_database,
     check_not_system_table,
     encoded_branch_name
 )
@@ -324,6 +325,7 @@ class JdbcCatalog(Catalog):
 
     def create_database(self, name: str, ignore_if_exists: bool,
                         properties: Optional[Dict[str, str]] = None) -> None:
+        check_not_system_database(name)
         if self._database_exists(name):
             if not ignore_if_exists:
                 raise DatabaseAlreadyExistException(name)
@@ -337,6 +339,7 @@ class JdbcCatalog(Catalog):
             self._insert_database_properties(name, create_props)
 
     def drop_database(self, name: str, ignore_if_not_exists: bool = False, 
cascade: bool = False) -> None:
+        check_not_system_database(name)
         if not self._database_exists(name):
             if not ignore_if_not_exists:
                 raise DatabaseNotExistException(name)
@@ -362,6 +365,7 @@ class JdbcCatalog(Catalog):
             )
 
     def alter_database(self, name: str, changes: List[PropertyChange]) -> None:
+        check_not_system_database(name)
         self.get_database(name)
         set_properties, remove_keys = 
PropertyChange.get_set_properties_to_remove_keys(changes)
         current = self._fetch_database_properties(name)
diff --git a/paimon-python/pypaimon/catalog/rest/rest_catalog.py 
b/paimon-python/pypaimon/catalog/rest/rest_catalog.py
index 2289eaa174..0974079c53 100644
--- a/paimon-python/pypaimon/catalog/rest/rest_catalog.py
+++ b/paimon-python/pypaimon/catalog/rest/rest_catalog.py
@@ -28,7 +28,7 @@ from pypaimon.api.rest_exception import 
(NoSuchResourceException, AlreadyExistsE
 from pypaimon.catalog.catalog import Catalog
 from pypaimon.catalog.catalog_context import CatalogContext
 from pypaimon.catalog.catalog_environment import CatalogEnvironment
-from pypaimon.catalog.catalog_utils import check_not_branch, 
check_not_system_table
+from pypaimon.catalog.catalog_utils import check_not_branch, 
check_not_system_database, check_not_system_table
 from pypaimon.catalog.catalog_exception import (
     ColumnAlreadyExistException, ColumnNotExistException,
     TableNotExistException, DatabaseAlreadyExistException,
@@ -164,6 +164,7 @@ class RESTCatalog(Catalog):
 
     def create_database(self, name: str, ignore_if_exists: bool,
                         properties: Optional[Dict[str, str]] = None) -> None:
+        check_not_system_database(name)
         try:
             self.rest_api.create_database(name, properties)
         except AlreadyExistsException as e:
@@ -187,6 +188,7 @@ class RESTCatalog(Catalog):
             raise DatabaseNoPermissionException(name) from e
 
     def drop_database(self, name: str, ignore_if_not_exists: bool = False, 
cascade: bool = False) -> None:
+        check_not_system_database(name)
         if not cascade:
             try:
                 tables = self.list_tables(name)
@@ -209,6 +211,7 @@ class RESTCatalog(Catalog):
             raise DatabaseNoPermissionException(name) from e
 
     def alter_database(self, name: str, changes: List[PropertyChange]) -> None:
+        check_not_system_database(name)
         try:
             set_properties, remove_keys = 
PropertyChange.get_set_properties_to_remove_keys(changes)
             self.rest_api.alter_database(name, list(remove_keys), 
set_properties)
diff --git a/paimon-python/pypaimon/tests/catalog_table_guard_test.py 
b/paimon-python/pypaimon/tests/catalog_table_guard_test.py
index 2787b04963..bf7ed0c852 100644
--- a/paimon-python/pypaimon/tests/catalog_table_guard_test.py
+++ b/paimon-python/pypaimon/tests/catalog_table_guard_test.py
@@ -24,6 +24,8 @@ import unittest
 import pyarrow as pa
 
 from pypaimon import CatalogFactory, Schema
+from pypaimon.catalog.catalog import Catalog
+from pypaimon.catalog.rest.property_change import PropertyChange
 from pypaimon.common.identifier import Identifier
 from pypaimon.schema.data_types import AtomicType
 from pypaimon.schema.schema_change import SchemaChange
@@ -79,6 +81,25 @@ def assert_table_guards(test, catalog, database):
     catalog.drop_table(Identifier(database, 'm2', branch='main'), False)
     test.assertEqual(catalog.list_tables(database), ['t'])
 
+    # As in Java, the sys database and the tables in it cannot be created, 
dropped or changed.
+    operations = [
+        lambda: catalog.create_database('sys', True),
+        lambda: catalog.drop_database('sys', True),
+        lambda: catalog.create_table('sys.t', schema, True),
+        lambda: catalog.drop_table('sys.t', True),
+        lambda: catalog.rename_table(name, 'sys.t'),
+        lambda: catalog.alter_table('sys.t', [add_column]),
+    ]
+    if type(catalog).alter_database is not Catalog.alter_database:
+        operations.append(lambda: catalog.alter_database('sys', 
[PropertyChange.set_property('k', 'v')]))
+    for operation in operations:
+        with test.assertRaises(ValueError):
+            operation()
+    with test.assertRaisesRegex(ValueError, "Can't do operation on system 
database."):
+        catalog.create_database('sys', False)
+    test.assertNotIn('sys', catalog.list_databases())
+    test.assertEqual(catalog.list_tables(database), ['t'])
+
 
 class CatalogTableGuardTest(unittest.TestCase):
 

Reply via email to