Skip to content

Error: Spatial queries sent to the OEP API using oedialect and a payload containing crs as a string (“4326”) fail. #405

Description

@jh-RLI

Users reported to me that they run into a strange error when they run dingo and want to get the data from the OEP. There the error log is:

ERROR 09/Sep/2025 19:10:11,597 log Internal Server Error: /api/v0/advanced/search
....
psycopg2.errors.InternalError_: could not parse proj string '4326'
CONTEXT:  SQL function "st_transform" statement 1

Here sqlachemy + oedialect are involved. I knew that there are issues with the oedialect so it took me some time to figure out what the issue is. As the error states there is some place in your code where the CRS is expected as int value but is availabe as string.

TO verify that i tried to run a request against the OEP using a similar query. Using the code below ... which worked perfectly:

Note the 4326 which is given as int value. If you change that to string the same error is raised.

import requests




PRODCTION_OEP_URL = "https://openenergyplatform.org"


PRODCTION_HEADER = {"Authorization": "Token *********"}

REST_API = "/api/v0"
ADVANCED_API = "/api/v0/advanced/search"
ADVANCED_API_COlUMNS = "/api/v0/advanced/get_columns"


if USE_LOCAL:
    pass

if not USE_LOCAL:
    query = {
        "fields": [
            {
                "type": "function",
                "function": "ST_AsGeoJSON",
                "operands": [
                    {
                        "type": "function",
                        "function": "ST_Transform",
                        "operands": [{"type": "column", "column": "geom"}, 4326],
                    }
                ],
            }
        ],
        "from": {"type": "table", "table": "ego_grid_ding0_mv_grid", "schema": "grid"},
    }

    response = requests.post(
        url=f"{PRODCTION_OEP_URL}{ADVANCED_API}",
        # headers=PRODCTION_HEADER,
        json={"query": query},
    )


print(response.json())
# print(response.json()["data"])
print(response.reason)

Then i set up ding0 locally using python 3.8 to debug this further. When i print out the data ding0 attempts to send to in the request to the oep i see that CRS is given as string ("4326") value. I stopped here, maybe this is a good hint for you @nesnoj where this happens?:

Internal Server Error advanced/search {
    "query": {
        "type": "select",
        "distinct": true,
        "fields": [
            {
                "type": "column",
                "column": "subst_id",
                "is_literal": false,
                "table": "ego_dp_mv_griddistrict",
                "schema": "grid"
            },
            {
                "type": "label",
                "element": {
                    "type": "function",
                    "function": "ST_AsText",
                    "operands": {
                        "type": "grouping",
                        "grouping": [
                            {
                                "type": "function",
                                "function": "ST_Transform",
                                "operands": {
                                    "type": "grouping",
                                    "grouping": [
                                        {
                                            "type": "column",
                                            "column": "geom",
                                            "is_literal": false,
                                            "table": "ego_dp_mv_griddistrict",
                                            "schema": "grid"
                                        },
                                        "4326"
                                    ]
                                }
                            }
                        ]
                    }
                },
                "label": "poly_geom"
            },
            {
                "type": "label",
                "element": {
                    "type": "function",
                    "function": "ST_AsText",
                    "operands": {
                        "type": "grouping",
                        "grouping": [
                            {
                                "type": "function",
                                "function": "ST_Transform",
                                "operands": {
                                    "type": "grouping",
                                    "grouping": [
                                        {
                                            "type": "column",
                                            "column": "point",
                                            "is_literal": false,
                                            "table": "ego_dp_hvmv_substation",
                                            "schema": "grid"
                                        },
                                        "4326"
                                    ]
                                }
                            }
                        ]
                    }
                },
                "label": "subs_geom"
            }
        ],
        "from": [
            {
                "type": "join",
                "join_type": "JOIN ",
                "left": {
                    "type": "table",
                    "schema": "grid",
                    "table": "ego_dp_mv_griddistrict"
                },
                "right": {
                    "type": "table",
                    "schema": "grid",
                    "table": "ego_dp_hvmv_substation"
                },
                "on": {
                    "type": "operator",
                    "operands": [
                        {
                            "type": "column",
                            "column": "subst_id",
                            "is_literal": false,
                            "table": "ego_dp_mv_griddistrict",
                            "schema": "grid"
                        },
                        {
                            "type": "column",
                            "column": "subst_id",
                            "is_literal": false,
                            "table": "ego_dp_hvmv_substation",
                            "schema": "grid"
                        }
                    ],
                    "operator": " = "
                }
            }
        ],
        "where": {
            "type": "operator",
            "operator": " AND ",
            "operands": [
                {
                    "type": "operator",
                    "operator": " AND ",
                    "operands": [
                        {
                            "type": "operator",
                            "operands": [
                                {
                                    "type": "column",
                                    "column": "subst_id",
                                    "is_literal": false,
                                    "table": "ego_dp_mv_griddistrict",
                                    "schema": "grid"
                                },
                                {
                                    "type": "grouping",
                                    "grouping": [
                                        460
                                    ]
                                }
                            ],
                            "operator": " IN "
                        },
                        {
                            "type": "operator",
                            "operands": [
                                {
                                    "type": "column",
                                    "column": "version",
                                    "is_literal": false,
                                    "table": "ego_dp_mv_griddistrict",
                                    "schema": "grid"
                                },
                                "v0.4.5"
                            ],
                            "operator": " = "
                        }
                    ]
                },
                {
                    "type": "operator",
                    "operands": [
                        {
                            "type": "column",
                            "column": "version",
                            "is_literal": false,
                            "table": "ego_dp_hvmv_substation",
                            "schema": "grid"
                        },
                        "v0.4.5"
                    ],
                    "operator": " = "
                }
            ]
        },
        "connection_id": 7574262158457431796,
        "cursor_id": 1067332787219545109
    },
    "connection_id": 7574262158457431796,
    "cursor_id": 1067332787219545109
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions