Repository: OpenEnergyPlatform/oeplatform

Issue:
CI is failing without any changes to the workflow setup.
The CI is failing, nothing changed on the related files... but still for some reason the CI is not setting up the environment variable to connect to the test database and then fails because no connection can be made.
I thought it was because the CI is running on ubuntu latest and there is currently being upgraded to ubuntu 22. But explicit switch back to 20.04 resolves an error, but does not change the basic problem.

Yesterday it was working :)

-> Full CI report 
https://github.com/OpenEnergyPlatform/oeplatform/actions/runs/3649748253/jobs/6164826060

Errors i checked on (but not solved)
- **(on ubuntu 22, not visible in 20.04)** ERROR: ld.so: object '/lib/x86_64-linux-gnu/libSegFault.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.  
related to:? https://github.com/OpenEnergyPlatform/oeplatform/blob/03a81926707e6422247307d61a0a8210e2cfdcee/.github/workflows/automated-testing.yaml#L15

- Changing ubuntu versions from latest to 20.04

Maybe someone else got an idea?
Multiple definitions of primary key error when defining PK on table column
See https://github.com/OpenEnergyPlatform/oedialect/issues/43 for reference

I will add a small PR to address this.


Discussion:

Resolving patch:
diff --git a/api/actions.py b/api/actions.py
--- a/api/actions.py
+++ b/api/actions.py
@@ -38,7 +38,6 @@
 from dataedit.structures import Tag as OEDBTag
 from oeplatform.securitysettings import PLAYGROUNDS, UNVERSIONED_SCHEMAS
 
-
 pgsql_qualifier = re.compile(r"^[\w\d_\.]+$")
 
 
@@ -108,9 +107,9 @@ def assert_permission(user, table, permission, schema=None):
 
 def assert_add_tag_permission(user, table, permission, schema):
     """
-    Tags can be added to tables that are in any schema. However, 
-    it is necessary to check whether the user has write permission 
-    to the table, since not every user should be able to add tags 
+    Tags can be added to tables that are in any schema. However,
+    it is necessary to check whether the user has write permission
+    to the table, since not every user should be able to add tags
     to every table.
 
     Args:
@@ -121,7 +120,7 @@ def assert_add_tag_permission(user, table, permission, schema):
 
     Raises:
         PermissionDenied: _description_
-    
+
     """
     # if not request.user.is_anonymous:
     #         level = request.user.get_table_permission_level(table)
@@ -866,6 +865,10 @@ def table_create(schema, table, column_definitions, constraints_definitions):
                 ccolumns = [constraint["constraint_parameter"]]
 
             if primary_key_col_names:
+                # if table level PK constraint is set in addition
+                # to column level PK, both must be the same (#1110)
+                if set(ccolumns) == set(primary_key_col_names):
+                    continue
                 raise APIError("Multiple definitions of primary key")
             primary_key_col_names = ccolumns
 
@@ -2293,7 +2296,7 @@ def set_table_metadata(table, schema, metadata, cursor=None):
     # update the table comment in oedb table if sqlalchemy curser is provided
     # ---------------------------------------
 
-    # TODO: The following 2 lines seems to duplicate with the lines below the if block 
+    # TODO: The following 2 lines seems to duplicate with the lines below the if block
     oedb_table_obj = _get_table(schema=schema, table=table)
     oedb_table_obj.comment = metadata_str
     if cursor is not None:


Test patch:
diff --git a/api/tests/test_regression/test_issue_739_enforce_id_pk.py b/api/tests/test_regression/test_issue_739_enforce_id_pk.py
--- a/api/tests/test_regression/test_issue_739_enforce_id_pk.py
+++ b/api/tests/test_regression/test_issue_739_enforce_id_pk.py
@@ -108,3 +108,18 @@ def test_err_on_multiple_pk(self):
             }
         )
         self.assertEqual(res.status_code, 400)
+
+    def test_ok_on_double_defined_pk(self):
+        """sqlalchemy sets column attribute primary_key=True
+        in addition to primary, which should work. (#1110)
+        """
+        res = self.create_table(
+            {
+                "columns": [
+                    {"name": "id", "data_type": "int", "primary_key": True},
+                    {"name": "value", "data_type": "int"},
+                ],
+                "constraints": [{"type": "primary_key", "columns": ["id"]}],
+            }
+        )
+        self.assertEqual(res.status_code, 201)