Skip to content

DB errors during deserialization of user input #1922

Description

@Flix6x

Two examples for replicating the issue:

In the CLI

Run flexmeasures show account --id foo.

Observed:

sqlalchemy.exc.DataError: (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "foo"
LINE 3: WHERE account.id = 'foo'
                           ^

[SQL: SELECT account.id AS account_id, account.name AS account_name, account.primary_color AS account_primary_color, account.secondary_color AS account_secondary_color, account.logo_url AS account_logo_url, account.consultancy_account_id AS account_consultancy_account_id 
FROM account 
WHERE account.id = %(pk_1)s]
[parameters: {'pk_1': 'foo'}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)

Expected:

Error: Invalid value for '--id': Not a valid integer.

In the UI

Visit http://localhost:5000/api/v3_0/sensors/14/data?start=2023-01-01T00:00+01&duration=P1D&unit=EUR/MWh&source=[1,%2014]

Observed:

{
  "message": "(psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: \"[1, 14]\"\nLINE 3: WHERE data_source.id = '[1, 14]'\n                               ^\n\n[SQL: SELECT data_source.type AS data_source_type, data_source.user_id AS data_source_user_id, data_source.attributes AS data_source_attributes, data_source.attributes_hash AS data_source_attributes_hash, data_source.model AS data_source_model, data_source.version AS data_source_version, data_source.id AS data_source_id, data_source.name AS data_source_name \nFROM data_source \nWHERE data_source.id = %(pk_1)s]\n[parameters: {'pk_1': '[1, 14]'}]\n(Background on this error at: https://sqlalche.me/e/20/9h9h)",
  "status": 500
}

Expected:

{
  "message": {
    "combined_sensor_data_description": {
      "source": [
        "Not a valid integer."
      ]
    }
  },
  "result": "Rejected",
  "status": "UNPROCESSABLE_ENTITY"
}

I already started work on a fix and will make the PR soon.

Metadata

Metadata

Assignees

Labels

APICLIbugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions