These are chat archives for CharlesGust/django-imagr
So I'm going through your fabfile, alongside Chris' tutorial. The provision_instance() function is broken as well I can tell (Chris' originally, which was copied). I don't even feel the need to test it. I know it doesn't work. Two glaring errors:
1) (As I take it you noticed from the "# !" comment you left on the line) The "i" in:
running_instance.append(new_instances.pop(new_instances.index(i))) doesn't refer to anything. I'm guessing "each_instance" is what's meant to be referenced here because it is a line in a for-loop that is iterating over 'new_instances' with 'each_instance'.
2) Much more importantly, you can't pop() from a list as that list is being iterated over because the indicies being referenced get all fucked up. E.g, If i define mylist = [1, 2, 3, 4], and I say:
for item in mylist:
if item > 2:
mylist will now be = [1, 2, 4]. I assume that this is because 3 was at index 2, and the built-in 'for x in lst' construction keeps track of indicies to iterate over the list. So after it is determined that the current item satisfies the condition and is popped from the list, 4 is now at index 2. But since index 2 has already been checked, the loop moves on to index 3, which doesn't exist anymore and so the loop ends, leaving 4 (even though 4 > 2)
And, as you said, the pop() part also doesn't work.
for item in list:
if item > 2:
will, as you said, fail to handle indices correctly after the first item has been removed.