Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wire up valid_target_type function to column lister #3709

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,8 @@ Each returned JSON object in the array will have the form:
"primary_key": <bool>,
"default": {"value": <str>, "is_dynamic": <bool>},
"has_dependents": <bool>,
"description": <str>
"description": <str>,
"valid_target_types": [<str>, <str>, ...]
}

The `type_options` object is described in the docstring of `msar.get_type_options`. The `default`
Expand Down Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -2568,7 +2569,8 @@ BEGIN
"scale": null,
"precision": null
},
"has_dependents": false
"has_dependents": false,
"valid_target_types": null
},
{
"id": 3,
Expand All @@ -2581,7 +2583,8 @@ BEGIN
"type_options": {
"length": 128
},
"has_dependents": false
"has_dependents": false,
"valid_target_types": null
},
{
"id": 4,
Expand All @@ -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,
Expand All @@ -2611,7 +2615,8 @@ BEGIN
"type_options": {
"precision": null
},
"has_dependents": false
"has_dependents": false,
"valid_target_types": null
},
{
"id": 6,
Expand All @@ -2624,7 +2629,8 @@ BEGIN
"type_options": {
"item_type": "integer"
},
"has_dependents": false
"has_dependents": false,
"valid_target_types": null
},
{
"id": 7,
Expand All @@ -2639,7 +2645,8 @@ BEGIN
"item_type": "numeric",
"precision": 15
},
"has_dependents": false
"has_dependents": false,
"valid_target_types": null
}
]$j$::jsonb
);
Expand Down
4 changes: 3 additions & 1 deletion mathesar/rpc/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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")
)


Expand Down
30 changes: 20 additions & 10 deletions mathesar/tests/rpc/columns/test_c_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,38 @@ 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},
'nullable': True,
'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
},
]

Expand All @@ -74,33 +79,38 @@ 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},
'nullable': True,
'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)
Expand Down
Loading