Suppose locale='es-AR' and the image does not exist, so you set locale='es-ES' on line 103. 

On line 106 you still check the path with es-AR defined at line 101, not a patch built from the new value of locale, so you fall back to en-US (settings.LANGUAGE_CODE). 

Am I reading it wrong?