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

Cursor pagination, sqlalchemy and lazy joined #1121

Open
Nnonexistent opened this issue Apr 10, 2024 · 2 comments
Open

Cursor pagination, sqlalchemy and lazy joined #1121

Nnonexistent opened this issue Apr 10, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Nnonexistent
Copy link

When using lazy="joined" in sqlalchemy model relationship with cursor pagination, the pagination will fail with the message:

The unique() method must be invoked on this Result, as it contains results that include joined eager loads against collections

Example (slightly modified test case initial condition):

class User(sa_base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String, nullable=False)

    orders = relationship("Order", back_populates="user", lazy="joined")  # <- here, instead of "noload"

The case is probably due to unique option from paginate is not propagated down to the sqlakeyset's implementation of the cursor pagination. So no _maybe_unique function is invoked leading to this error.

Maybe there is a way of workaround this issue without dropping use of lazy loading?

@uriyyo uriyyo self-assigned this Apr 10, 2024
@uriyyo uriyyo added the bug Something isn't working label Apr 10, 2024
@uriyyo
Copy link
Owner

uriyyo commented Apr 15, 2024

Hi @Nnonexistent,

It's a kinda tricky thing, I guess we need to open issue in sqlakeyset.

As a workaround you can try to change joinedload to selectinload, it will not require you to call unique.

@uriyyo
Copy link
Owner

uriyyo commented Oct 4, 2024

Hi @Nnonexistent,

Looks like this issue has been fixed on sqlakeyset side - djrobstep/sqlakeyset@912757d

Could you please try to reproduce it?

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
None yet
Development

No branches or pull requests

2 participants