From e68c87603a41c281e67230baa951918f7453228b Mon Sep 17 00:00:00 2001 From: Brent Moran Date: Thu, 25 Jul 2024 18:18:28 +0800 Subject: [PATCH 1/2] wire up valid_target_type function to column lister --- db/sql/00_msar.sql | 6 +++-- db/sql/test_00_msar.sql | 21 ++++++++++------ mathesar/rpc/columns/base.py | 4 ++- mathesar/tests/rpc/columns/test_c_base.py | 30 +++++++++++++++-------- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/db/sql/00_msar.sql b/db/sql/00_msar.sql index aac6ddddc7..87298e948d 100644 --- a/db/sql/00_msar.sql +++ b/db/sql/00_msar.sql @@ -753,7 +753,8 @@ Each returned JSON object in the array will have the form: "primary_key": , "default": {"value": , "is_dynamic": }, "has_dependents": , - "description": + "description": , + "valid_target_types": [, , ...] } The `type_options` object is described in the docstring of `msar.get_type_options`. The `default` @@ -784,7 +785,8 @@ SELECT jsonb_agg( jsonb_build_object() ), 'has_dependents', msar.has_dependents(tab_id, attnum), - 'description', msar.col_description(tab_id, attnum) + 'description', msar.col_description(tab_id, attnum), + 'valid_target_types', msar.get_valid_target_type_strings(atttypid) ) ) FROM pg_attribute pga diff --git a/db/sql/test_00_msar.sql b/db/sql/test_00_msar.sql index 5c10ad130a..9148fa52d3 100644 --- a/db/sql/test_00_msar.sql +++ b/db/sql/test_00_msar.sql @@ -2554,7 +2554,8 @@ BEGIN "description": null, "primary_key": true, "type_options": null, - "has_dependents": true + "has_dependents": true, + "valid_target_types": null }, { "id": 2, @@ -2568,7 +2569,8 @@ BEGIN "scale": null, "precision": null }, - "has_dependents": false + "has_dependents": false, + "valid_target_types": null }, { "id": 3, @@ -2581,7 +2583,8 @@ BEGIN "type_options": { "length": 128 }, - "has_dependents": false + "has_dependents": false, + "valid_target_types": null }, { "id": 4, @@ -2595,7 +2598,8 @@ BEGIN "description": "A super comment ;", "primary_key": false, "type_options": null, - "has_dependents": false + "has_dependents": false, + "valid_target_types": ["numeric", "text"] }, { "id": 5, @@ -2611,7 +2615,8 @@ BEGIN "type_options": { "precision": null }, - "has_dependents": false + "has_dependents": false, + "valid_target_types": null }, { "id": 6, @@ -2624,7 +2629,8 @@ BEGIN "type_options": { "item_type": "integer" }, - "has_dependents": false + "has_dependents": false, + "valid_target_types": null }, { "id": 7, @@ -2639,7 +2645,8 @@ BEGIN "item_type": "numeric", "precision": 15 }, - "has_dependents": false + "has_dependents": false, + "valid_target_types": null } ]$j$::jsonb ); diff --git a/mathesar/rpc/columns/base.py b/mathesar/rpc/columns/base.py index 257cfccf64..6c447541a8 100644 --- a/mathesar/rpc/columns/base.py +++ b/mathesar/rpc/columns/base.py @@ -170,6 +170,7 @@ class ColumnInfo(TypedDict): default: ColumnDefault has_dependents: bool description: str + valid_target_types: list[str] @classmethod def from_dict(cls, col_info): @@ -182,7 +183,8 @@ def from_dict(cls, col_info): primary_key=col_info["primary_key"], default=ColumnDefault.from_dict(col_info.get("default")), has_dependents=col_info["has_dependents"], - description=col_info.get("description") + description=col_info.get("description"), + valid_target_types=col_info.get("valid_target_types") ) diff --git a/mathesar/tests/rpc/columns/test_c_base.py b/mathesar/tests/rpc/columns/test_c_base.py index 657145f514..88f7db64f5 100644 --- a/mathesar/tests/rpc/columns/test_c_base.py +++ b/mathesar/tests/rpc/columns/test_c_base.py @@ -36,7 +36,8 @@ def mock_column_info(_table_oid, conn): 'default': {'value': 'identity', 'is_dynamic': True}, 'nullable': False, 'description': None, 'primary_key': True, 'type_options': None, - 'has_dependents': True + 'has_dependents': True, + 'valid_target_types': ['text'] }, { 'id': 2, 'name': 'numcol', 'type': 'numeric', 'default': {'value': "'8'::numeric", 'is_dynamic': False}, @@ -44,25 +45,29 @@ def mock_column_info(_table_oid, conn): 'description': 'My super numeric column', 'primary_key': False, 'type_options': {'scale': None, 'precision': None}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': ['text'] }, { 'id': 4, 'name': 'numcolmod', 'type': 'numeric', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'scale': 3, 'precision': 5}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': ['text'] }, { 'id': 8, 'name': 'ivlcolmod', 'type': 'interval', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'fields': 'day to second'}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': ['text'] }, { 'id': 10, 'name': 'arrcol', 'type': '_array', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'item_type': 'character varying', 'length': 3}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': None }, ] @@ -74,7 +79,8 @@ def mock_column_info(_table_oid, conn): 'default': {'value': 'identity', 'is_dynamic': True}, 'nullable': False, 'description': None, 'primary_key': True, 'type_options': None, - 'has_dependents': True + 'has_dependents': True, + 'valid_target_types': ['text'] }, { 'id': 2, 'name': 'numcol', 'type': 'numeric', 'default': {'value': "'8'::numeric", 'is_dynamic': False}, @@ -82,25 +88,29 @@ def mock_column_info(_table_oid, conn): 'description': 'My super numeric column', 'primary_key': False, 'type_options': None, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': ['text'] }, { 'id': 4, 'name': 'numcolmod', 'type': 'numeric', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'scale': 3, 'precision': 5}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': ['text'] }, { 'id': 8, 'name': 'ivlcolmod', 'type': 'interval', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'fields': 'day to second'}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': ['text'] }, { 'id': 10, 'name': 'arrcol', 'type': '_array', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'item_type': 'character varying', 'length': 3}, - 'has_dependents': False + 'has_dependents': False, + 'valid_target_types': None } ] actual_col_list = columns.list_(table_oid=23457, database_id=database_id, request=request) From 6cb4767b080ec405f2751508aaf3f4ed5fb34989 Mon Sep 17 00:00:00 2001 From: Brent Moran Date: Thu, 25 Jul 2024 21:57:37 +0800 Subject: [PATCH 2/2] add doc for valid_target_types attribute --- mathesar/rpc/columns/base.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mathesar/rpc/columns/base.py b/mathesar/rpc/columns/base.py index 6c447541a8..1b0f5e954d 100644 --- a/mathesar/rpc/columns/base.py +++ b/mathesar/rpc/columns/base.py @@ -160,6 +160,8 @@ class ColumnInfo(TypedDict): default: The default value and whether it's dynamic. has_dependents: Whether the column has dependent objects. description: The description of the column. + valid_target_types: A list of all types to which the column can + be cast. """ id: int name: str