coderholic / django-cities

Countries and cities of the world for Django projects
MIT License
930 stars 374 forks source link

UnboundLocalError: cannot access local variable 'url' where it is not associated with a value #245

Open mohsen-mahmoodi opened 1 week ago

mohsen-mahmoodi commented 1 week ago

Checklist

Steps to reproduce

Configure CITIES_FILES for a pre-downloaded file without URL:

CITIES_FILES = {
        'country': {
            'filename': 'not-existing',
            'urls': []
        },
}

Run the import command:

python manage.py cities --import=country

Expected behavior

Exception: File not found and download failed: citiesxx500.zip [[]]

Actual behavior

UnboundLocalError: cannot access local variable 'url' where it is not associated with a value

Reason

In the file cities/management/commands/citities.py method def download(self, filekey):, we have a line to raise an exception like this:

raise Exception("File not found and download failed: {} [{}]".format(filename, url))

It should be changed to:

raise Exception("File not found and download failed: {} [{}]".format(filename, urls))