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

Constant _PAGE_0 updated during pagination #162

Closed
KirbyElder opened this issue Apr 25, 2023 · 2 comments
Closed

Constant _PAGE_0 updated during pagination #162

KirbyElder opened this issue Apr 25, 2023 · 2 comments

Comments

@KirbyElder
Copy link

I kept finding that repeated calls to Daft.search() were giving me incorrect results, so I did some digging.

_PAGE_0 = {"from": "0", "pagesize": str(_PAGE_SZ)} is a dictionary used when creating a new Daft instance to start pagination from 0.

However, when this is assigned:

self._paging = self._PAGE_0

The reference to the constant gets passed, not a copy. Later on, when we edit self._paging to say we should paginate from the 50th result, we also modify the constant.
Creating a new instance of Daft will result in beginning with the constant in the state the other instance left it in. Calling search() with the same instance of Daft has similar issues since this value is never returned to 0 as far as I can tell.

I have a dumb workaround to this, which is that I make a new instance and manually fix the constant _PAGE_0 each time before instantiation, but this is a dumb workaround.

Daft._PAGE_0 = {"from": "0", "pagesize": str(Daft._PAGE_SZ)}
daft = Daft()
@sdfordham
Copy link
Collaborator

Yes this is a dumb bug, I propose deepcopy in the payload fn, Ill add a PR for this.

AnthonyBloomer added a commit that referenced this issue Apr 27, 2023
@AnthonyBloomer
Copy link
Owner

Thanks for reporting this issue. Published a new version to PyPi that fixes this: https://pypi.org/project/daftlistings/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants