Repository: mathesar-foundation/mathesar

Issue:
Couldn't create new rows for the tables that use IDENTITY for their id columns.
## Description
<!-- A clear and concise description of what the bug is. -->
We have moved to using a different method for ids generations for our default id column as discussed [here](https://github.com/centerofci/mathesar/pull/3016), however this results in an inablility to create new rows using the ui.

![Screenshot from 2023-08-02 17-23-18](https://github.com/centerofci/mathesar/assets/52523023/7de5498c-a354-4405-8c2f-aa796e4588a0)

For some reason the call to the `records/` api isn't being made. Using the browsable api works as expected.

## Expected behavior
<!-- A clear and concise description of what you expected to happen. -->
We should be able to use the ui to create rows for this kind of tables. 

## To Reproduce
<!-- How can we recreate this bug? Please try to provide a Minimal, Complete, and Verifiable (http://stackoverflow.com/help/mcve) example if code-related. -->
- Create a new table using the psql shell: `SELECT msar.add_mathesar_table(2200, 'test_table', NULL, NULL, NULL);` <-- This will create a new table in your `public` shema.
- Sync external changes.
- Try to add new rows to that table. 




Discussion:

Resolving patch:
diff --git a/db/columns/operations/select.py b/db/columns/operations/select.py
--- a/db/columns/operations/select.py
+++ b/db/columns/operations/select.py
@@ -1,6 +1,6 @@
 import warnings
 
-from sqlalchemy import and_, asc, cast, select, text, exists
+from sqlalchemy import and_, asc, cast, select, text, exists, Identity
 
 from db.columns.exceptions import DynamicDefaultWarning
 from db.connection import execute_msar_func_with_engine
@@ -118,14 +118,16 @@ def get_column_default_dict(table_oid, attnum, engine, metadata, connection_to_u
         metadata=metadata,
         connection_to_use=connection_to_use,
     )
+    default = column.server_default
 
-    if column.server_default is None:
+    if default is None:
         return
 
     is_dynamic = execute_msar_func_with_engine(
         engine, 'is_default_possibly_dynamic', table_oid, attnum
     ).fetchone()[0]
-    sql_text = str(column.server_default.arg)
+
+    sql_text = str(default.arg) if not isinstance(default, Identity) else 'identity'
 
     if is_dynamic:
         warnings.warn(


Test patch:
diff --git a/db/sql/test_0_msar.sql b/db/sql/test_0_msar.sql
--- a/db/sql/test_0_msar.sql
+++ b/db/sql/test_0_msar.sql
@@ -1544,3 +1544,32 @@ BEGIN
   RETURN NEXT col_not_null('col_alters', 'timecol');
 END;
 $f$ LANGUAGE plpgsql;
+
+
+CREATE OR REPLACE FUNCTION setup_dynamic_defaults() RETURNS SETOF TEXT AS $$
+BEGIN
+  CREATE TABLE defaults_test (
+    id integer PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
+    col1 integer DEFAULT 5,
+    col2 integer DEFAULT 3::integer,
+    col3 timestamp DEFAULT NOW(),
+    col4 date DEFAULT '2023-01-01',
+    col5 date DEFAULT CURRENT_DATE
+  );
+END;
+$$ LANGUAGE plpgsql;
+
+
+CREATE OR REPLACE FUNCTION test_is_possibly_dynamic() RETURNS SETOF TEXT AS $$
+DECLARE
+  tab_id oid;
+BEGIN
+  tab_id := 'defaults_test'::regclass::oid;
+  RETURN NEXT is(msar.is_default_possibly_dynamic(tab_id, 1), true);
+  RETURN NEXT is(msar.is_default_possibly_dynamic(tab_id, 2), false);
+  RETURN NEXT is(msar.is_default_possibly_dynamic(tab_id, 3), false);
+  RETURN NEXT is(msar.is_default_possibly_dynamic(tab_id, 4), true);
+  RETURN NEXT is(msar.is_default_possibly_dynamic(tab_id, 5), false);
+  RETURN NEXT is(msar.is_default_possibly_dynamic(tab_id, 6), true);
+END;
+$$ LANGUAGE plpgsql;