I have a flask application (Python 3 / Flask 2.2.5) which I am doing a once-off import of data using a flask custom command, the data is being imported via an API.
As there are many thousands of items, I am first chunking the API requests into groups of 100 items. Each item has a unique ID which is an integer.
I am creating a python list of those integers which I want to first check to see if they already exist locally in the database, and if they do – remove them from the list before building the request.
When I iterate over the list I am seeing what appears to be every second item disappearing from the list causing them to be skipped by my local database check.
My list looks like:
print(type(items_list), items_list)
<class 'list'> [18, 19, 20, 21, 22, 25, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260]
If I then iterate over that list, I can see that every second item is missing, for example ID’s 19, 21, 35, 37, etc are missing.
for z in items_list:
print("TRYING", z)
TRYING 18
TRYING 20
TRYING 22
TRYING 34
TRYING 36
TRYING 38
TRYING 40
TRYING 42
TRYING 44
<snip>
I’ve tried running it manually via a flask shell, and the behavior is consistent with the above.
Thanks in advance.
Jacob Gardiner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.