Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with two refs on single model #227

Closed
sirex opened this issue Apr 22, 2022 · 0 comments
Closed

Bug with two refs on single model #227

sirex opened this issue Apr 22, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@sirex
Copy link
Collaborator

sirex commented Apr 22, 2022

Issue when joining two different references from one table. Example:

    (
        child_standard._id  = "d1ec0813-3dde-436b-8244-d726c1e1d7b4" |
        parent_standard._id = "d1ec0813-3dde-436b-8244-d726c1e1d7b4"
    )
    &
    select(
        _id,
        parent_standard.standard_reference,
        child_standard.standard_reference,
        standard_relation_type.name
    )
Traceback (most recent call last):
  File "spinta/api.py", line 91, in homepage
    return await create_http_response(context, params, request)
  File "spinta/utils/response.py", line 165, in create_http_response
    return await commands.getall(
  File "spinta/commands/read.py", line 96, in getall
    return render(context, request, model, params, rows, action=action)
  File "spinta/renderer.py", line 22, in render
    return commands.render(
  File "spinta/formats/html/commands.py", line 135, in render
    return _render_model(context, request, model, action, params, data, headers)
  File "spinta/formats/html/commands.py", line 239, in _render_model
    ctx = _build_template_context(
  File "spinta/formats/html/commands.py", line 213, in _build_template_context
    rows, empty = _is_empty(rows)
  File "spinta/formats/html/commands.py", line 167, in _is_empty
    row = next(rows)
  File "spinta/utils/nestedstruct.py", line 15, in flatten
    for v in vals:
  File "spinta/commands/read.py", line 84, in <genexpr>
    rows = (
  File "spinta/backends/postgresql/commands/read.py", line 110, in getall
    result = conn.execute(qry)
  File "sqlalchemy/engine/base.py", line 1200, in execute
    return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
  File "sqlalchemy/sql/elements.py", line 313, in _execute_on_connection
    return connection._execute_clauseelement(
  File "sqlalchemy/engine/base.py", line 1389, in _execute_clauseelement
    ret = self._execute_context(
  File "sqlalchemy/engine/base.py", line 1748, in _execute_context
    self._handle_dbapi_exception(
  File "sqlalchemy/engine/base.py", line 1929, in _handle_dbapi_exception
    util.raise_(
  File "sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "sqlalchemy/engine/base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "sqlalchemy/engine/default.py", line 716, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError:
    (psycopg2.errors.DuplicateAlias) table name "Standard" specified more than once
SELECT
  "RelatedStandard"._id,
  "RelatedStandard"._revision,
  "Standard".standard_reference AS "parent_standard.standard_reference",
  "Standard".standard_reference AS "child_standard.standard_reference",
  "StandardRelationType".name AS "standard_relation_type.name"
FROM "RelatedStandard"
JOIN "Standard" ON "RelatedStandard"."parent_standard._id" = "Standard"._id
JOIN "Standard" ON "RelatedStandard"."child_standard._id" = "Standard"._id
JOIN "StandardRelationType" ON "RelatedStandard"."standard_relation_type._id" = "StandardRelationType"._id
WHERE
  "RelatedStandard"."child_standard._id"  = 'd1ec0813-3dde-436b-8244-d726c1e1d7b4' OR
  "RelatedStandard"."parent_standard._id" = 'd1ec0813-3dde-436b-8244-d726c1e1d7b4'
LIMIT 101

The issue here, that Standard was joined two times, wihout using alias.

@sirex sirex closed this as completed in c92b56c Apr 22, 2022
Repository owner moved this from In Progress to Done in Portalo plėtra Apr 22, 2022
@sirex sirex added the bug Something isn't working label Apr 22, 2022
@sirex sirex added this to Palaikymas Nov 16, 2022
@sirex sirex removed this from Portalo plėtra Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant