OpenEnergyPlatform / oeplatform

Repository for the code of the Open Energy Platform (OEP) website. The OEP provides an interface to the Open Energy Family
http://openenergyplatform.org/
GNU Affero General Public License v3.0
62 stars 19 forks source link

Attempting to create a table using a duplicated id column leads to an error #1885

Closed jh-RLI closed 1 month ago

jh-RLI commented 1 month ago

Description of the issue

Creating a table using the API & a payload like this:

table_schema = {
    "columns": [
        {"name": "id", "data_type": "bigserial", "primary_key": True},
        {'name': 'id', 'data_type': 'integer'},
        {"name": "name", "data_type": "varchar(18)", "is_nullable": False},
        {"name": "is_active", "data_type": "boolean"},
        {"name": "capacity_mw", "data_type": "float"},
        {"name": "installation_datetime_utc", "data_type": "datetime"},
    ]
}

or without primary key but duplicated id fields

table_schema = {
    "columns": [
        # NOTE: first column should be numerical column named `id` .
        # Use `bigserial` if you want the database to create the re
        {"name": "id", "data_type": "bigserial", "is_nullable": "False"},
        {"name": "id", "data_type": "integer"},
        {"name": "name", "data_type": "varchar(18)", "is_nullable": False},
        {"name": "is_active", "data_type": "boolean"},
        {"name": "capacity_mw", "data_type": "float"},
        {"name": "installation_datetime_utc", "data_type": "datetime"},
    ]
}

On current develop, creating a table like this will result in an error that is not well caught. The resulting errors are that the table is created in the Django db but not in the oedb and also the permissions are not assigned because execution stops before assignment.

Steps to Reproduce

  1. Define two id columns in the table payload object (see above)
  2. Create a table using the api
  3. Try to access or delete the table

Ideas of solution

Workflow checklist