Skip to content

Support joins within OrderBy #404

@Skelmis

Description

@Skelmis

Currently it would appear that sorting based off of join's fails within the admin interface.

Example table code:

class ProjectAutomation(Table):
    id = UUID(primary_key=True, default=uuid.uuid4, index=True)
    project = ForeignKey(
        LazyTableReference("Project", app_name="home"),
        index=True,
        unique=True,
        help_text="The project this automation is for",
    )

class Project(Table):
    id = UUID(primary_key=True, default=uuid.uuid4, index=True)
    owner = ForeignKey(BaseUser, index=True, help_text="Who owns this project")

Code within create_admin that errors:

        order_by=[
            OrderBy(ProjectAutomation.project.owner),
        ],

Traceback cut to only Piccolo bits:

  File "/home/skelmis/.cache/pypoetry/virtualenvs/hermes-nZAhPr0C-py3.10/lib/python3.10/site-packages/piccolo_api/fastapi/endpoints.py", line 137, in get
    return await piccolo_crud.root(request=request)
  File "/home/skelmis/.cache/pypoetry/virtualenvs/hermes-nZAhPr0C-py3.10/lib/python3.10/site-packages/piccolo_api/crud/endpoints.py", line 606, in root
    return await self.get_all(request, params=params)
  File "/home/skelmis/.cache/pypoetry/virtualenvs/hermes-nZAhPr0C-py3.10/lib/python3.10/site-packages/piccolo_api/crud/validators.py", line 129, in inner_coroutine_function
    return await function(*args, **kwargs)
  File "/home/skelmis/.cache/pypoetry/virtualenvs/hermes-nZAhPr0C-py3.10/lib/python3.10/site-packages/piccolo_api/crud/endpoints.py", line 832, in get_all
    split_params = self._split_params(params)
  File "/home/skelmis/.cache/pypoetry/virtualenvs/hermes-nZAhPr0C-py3.10/lib/python3.10/site-packages/piccolo_api/crud/endpoints.py", line 694, in _split_params
    column = self._get_column(column_name=sub_value)
  File "/home/skelmis/.cache/pypoetry/virtualenvs/hermes-nZAhPr0C-py3.10/lib/python3.10/site-packages/piccolo_api/crud/endpoints.py", line 1101, in _get_column
    raise ValueError("Max join depth exceeded")
ValueError: Max join depth exceeded

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions