PokéBot Gen3 is a shiny hunting bot, written in Python that runs libmgba + mGBA Python bindings under the hood. Pokémon Ruby, Sapphire, Emerald, FireRed and LeafGreen are supported.
For the first API call, the statement is True which executes the line self._item_bag.value = item_bag
That line will then execute the generic value setter which resets the self.time of the StateCacheItem which makes it work
On the other API calls after that, the statement is False which essentially doesn't execute the generic value setter, that makes it so the StateCacheItem keeps it's old time and causes the infinite loop
The same issue happens with ItemStorage, not just the ItemBag
I wasn't sure what would be considered to best way to fix this issue so I decided to just create an Issue and not a pull request but I could always open one with a fix if needed.
Just a little recommendation I would like to make. Those while loops could have a stopping condition after a certain amount of time / tries and send an error response back so infinite loop can't occur
The first API call to items works but the consecutive calls only hangs
How to reproduce
While investigating this issue. I saw that this piece of code looked at the age in seconds of the cached value https://github.com/40Cakes/pokebot-gen3/blob/14b7bef57ab26d7f12109f4465b6928ae96bc543/modules/web/http.py#L129-L134
From what I found, the items endpoints hangs because the age in seconds never resets which causes an infinite loop
While looking through the code with a debugger, I found that it happens because of this if statement https://github.com/40Cakes/pokebot-gen3/blob/14b7bef57ab26d7f12109f4465b6928ae96bc543/modules/state_cache.py#L143-L146
For the first API call, the statement is True which executes the line
self._item_bag.value = item_bag
That line will then execute the generic value setter which resets the self.time of the StateCacheItem which makes it workOn the other API calls after that, the statement is False which essentially doesn't execute the generic value setter, that makes it so the StateCacheItem keeps it's old time and causes the infinite loop
The same issue happens with ItemStorage, not just the ItemBag
I wasn't sure what would be considered to best way to fix this issue so I decided to just create an Issue and not a pull request but I could always open one with a fix if needed.
Just a little recommendation I would like to make. Those while loops could have a stopping condition after a certain amount of time / tries and send an error response back so infinite loop can't occur