Error on file "/bricks/setlists/setlists.py", line 47
Closed this issue ยท 12 comments
Hi,
Thanks for a report. But I have no idea why "id" field is missing. Any details would be helpful. Can you post resp
json value?
The JSON:
{
"count":6,
"next":"None",
"previous":"None",
"results":[
{
"list_id":800685,
"quantity":1,
"include_spares":true,
"set":{
"set_num":"2651-1",
"name":"Circus Artists",
"year":1989,
"theme_id":632,
"num_parts":9,
"set_img_url":"https: //cdn.rebrickable.com/media/sets/2651-1/756.jpg",
"set_url":"https://rebrickable.com/sets/2651-1/circus-artists/",
"last_modified_dt":"2019-07-15T04:03:34.215841Z"
}
},
{
"list_id":800685,
"quantity":1,
"include_spares":true,
"set":{
"set_num":"2612-1",
"name":"Motorbike & Rider (PreSchool Scooter)",
"year":1988,
"theme_id":632,
"num_parts":2,
"set_img_url":"https://cdn.rebrickable.com/media/sets/2612-1/10638.jpg",
"set_url":"https://rebrickable.com/sets/2612-1/motorbike-rider-preschool-scooter/",
"last_modified_dt":"2019-11-23T16:19:47.747310Z"
}
},
{
"list_id":800685,
"quantity":1,
"include_spares":true,
"set":{
"set_num":"2629-1",
"name":"Tractor and Farm Machinery",
"year":1985,
"theme_id":632,
"num_parts":7,
"set_img_url":"https://cdn.rebrickable.com/media/sets/2629-1/14770.jpg",
"set_url":"https://rebrickable.com/sets/2629-1/tractor-and-farm-machinery/",
"last_modified_dt":"2019-07-18T21:56:44.314976Z"
}
},
{
"list_id":800685,
"quantity":1,
"include_spares":true,
"set":{
"set_num":"534-1",
"name":"Bath-Toy Boat",
"year":1978,
"theme_id":632,
"num_parts":3,
"set_img_url":"https://cdn.rebrickable.com/media/sets/534-1/14744.jpg",
"set_url":"https://rebrickable.com/sets/534-1/bath-toy-boat/",
"last_modified_dt":"2018-07-30T04:00:02.398438Z"
}
},
{
"list_id":800685,
"quantity":1,
"include_spares":true,
"set":{
"set_num":"2668-1",
"name":"Children's Zoo (Zoo Animal Antics)",
"year":1990,
"theme_id":632,
"num_parts":41,
"set_img_url":"https://cdn.rebrickable.com/media/sets/2668-1/15352.jpg",
"set_url":"https://rebrickable.com/sets/2668-1/childrens-zoo-zoo-animal-antics/",
"last_modified_dt":"2019-07-15T20:42:39.517787Z"
}
},
{
"list_id":800685,
"quantity":1,
"include_spares":true,
"set":{
"set_num":"2598-1",
"name":"Large Red Building Plate",
"year":2006,
"theme_id":505,
"num_parts":1,
"set_img_url":"https://cdn.rebrickable.com/media/sets/2598-1/2520.jpg",
"set_url":"https://rebrickable.com/sets/2598-1/large-red-building-plate/",
"last_modified_dt":"2022-09-01T21:05:34.235475Z"
}
}
]
}
I tried a fix by changing id
to list_id
in line 47, but still have the error log:
bricks | make: Leaving directory '/bricks/rebrickable'
bricks | Traceback (most recent call last):
bricks | File "/bricks/setlists/setlists.py", line 47, in <module>
bricks | list_id = resp["results"][i]["list_id"]
bricks | ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
bricks | KeyError: 'list_id'
It is strange ... I print resp["results"][i]
above the error line and there is an id
key available:
bricks | {'id': 800685, 'is_buildable': True, 'name': 'Borstel DUPLO', 'num_sets': 6}
I have the only one "Set List". And here is my json (resp
above the error line):
{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"id": 304743,
"is_buildable": true,
"name": "Set List",
"num_sets": 180
}
]
}
The id
field is present.
In your case it looks like that you have more than one list returned from rebrickable. Could you post your resp
with all that lists? Let's check that all of them have an id
field
Here you are, as far as I can see, ids are provided for all items:
{
"count":4,
"next":"None",
"previous":"None",
"results":[
{
"id":800685,
"is_buildable":true,
"name":"DUPLO ONE",
"num_sets":6
},
{
"id":800691,
"is_buildable":true,
"name":"LEGO ONE",
"num_sets":43
},
{
"id":799836,
"is_buildable":true,
"name":"DUPLO TWO",
"num_sets":14
},
{
"id":633125,
"is_buildable":true,
"name":"LEGO TWO",
"num_sets":50
}
]
}
The error occurs for the first item already as you can see from the first posted JSON.
For this snippet:
resp = {
"count": 4,
"next": "None",
"previous": "None",
"results": [
{
"id": 800685,
"is_buildable": True,
"name": "DUPLO ONE",
"num_sets": 6
},
{
"id": 800691,
"is_buildable": True,
"name": "LEGO ONE",
"num_sets": 43
},
{
"id": 799836,
"is_buildable": True,
"name": "DUPLO TWO",
"num_sets": 14
},
{
"id": 633125,
"is_buildable": True,
"name": "LEGO TWO",
"num_sets": 50
}
]
}
for i in range(resp["count"]):
list_id = resp["results"][i]["id"]
print(f"list_id={list_id}")
I have the following output:
list_id=800685
list_id=800691
list_id=799836
list_id=633125
Your first posted JSON looks like the value of resp
at line 55
. Do you still crash at line 47
?
Maybe we need a DEBUG mode with verbose output
I found the issue - the request was overwritten within the loop ๐
PR submitted!
I found the issue - the request was overwritten within the loop ๐
Great! Exactly!