Repository: mathesar-foundation/mathesar

Issue:
Updating import_verified in tables patch endpoint results in a 400
## Description
When trying to perform a patch on a table, updating `import_verified`, it results in a 400.

<img width="1155" alt="Screenshot 2021-08-16 at 7 59 44 PM" src="https://user-images.githubusercontent.com/11850603/129580123-f467c984-0a34-4de7-baab-4c04637aabbf.png">


## Expected behavior
`import_verified` should be updatable.



Discussion:

Resolving patch:
diff --git a/mathesar/models.py b/mathesar/models.py
--- a/mathesar/models.py
+++ b/mathesar/models.py
@@ -110,6 +110,9 @@ def clear_name_cache(self):
 
 
 class Table(DatabaseObject):
+    # These are fields whose source of truth is in the model
+    MODEL_FIELDS = ['import_verified']
+
     schema = models.ForeignKey('Schema', on_delete=models.CASCADE,
                                related_name='tables')
     import_verified = models.BooleanField(blank=True, null=True)
diff --git a/mathesar/views/api.py b/mathesar/views/api.py
--- a/mathesar/views/api.py
+++ b/mathesar/views/api.py
@@ -134,8 +134,19 @@ def partial_update(self, request, pk=None):
             data=request.data, context={'request': request}, partial=True
         )
         serializer.is_valid(raise_exception=True)
-
         table = self.get_object()
+
+        # Save the fields that are stored in the model.
+        present_model_fields = []
+        for model_field in table.MODEL_FIELDS:
+            if model_field in serializer.validated_data:
+                setattr(table, model_field, serializer.validated_data[model_field])
+                present_model_fields.append(model_field)
+        table.save()
+        for key in present_model_fields:
+            del serializer.validated_data[key]
+
+        # Save the fields that are stored in the underlying DB.
         table.update_sa_table(serializer.validated_data)
 
         # Reload the table to avoid cached properties


Test patch:
diff --git a/mathesar/tests/views/api/test_table_api.py b/mathesar/tests/views/api/test_table_api.py
--- a/mathesar/tests/views/api/test_table_api.py
+++ b/mathesar/tests/views/api/test_table_api.py
@@ -661,6 +661,30 @@ def test_table_partial_update(create_table, client):
     assert table.name == new_table_name
 
 
+def test_table_partial_update_import_verified(create_table, client):
+    table_name = 'NASA Table Import Verify'
+    table = create_table(table_name)
+
+    body = {'import_verified': True}
+    response = client.patch(f'/api/v0/tables/{table.id}/', body)
+
+    response_table = response.json()
+    assert response.status_code == 200
+    assert response_table['import_verified'] is True
+
+
+def test_table_partial_update_schema(create_table, client):
+    table_name = 'NASA Table Schema PATCH'
+    table = create_table(table_name)
+
+    body = {'schema': table.schema.id}
+    response = client.patch(f'/api/v0/tables/{table.id}/', body)
+
+    response_error = response.json()
+    assert response.status_code == 400
+    assert response_error['schema'] == 'Updating schema for tables is not supported.'
+
+
 def test_table_delete(create_table, client):
     table_name = 'NASA Table Delete'
     table = create_table(table_name)