AnthonyBloomer / daftlistings

A library that enables programmatic interaction with daft.ie. Daft.ie has nationwide coverage and contains about 80% of the total available properties in Ireland.
MIT License
171 stars 54 forks source link

Constant _PAGE_0 updated during pagination #162

Closed KirbyElder closed 1 year ago

KirbyElder commented 1 year ago

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 commented 1 year ago

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

AnthonyBloomer commented 1 year ago

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