-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
django-cities returns a MultipleObjectsReturned exception raised while importing #180
Comments
I am also encountering this issue. As you can see from the traceback above, the problem is that there are Subregion objects that are non-unique by a combination of region name, subregion name, and country. I've determined that there are, in fact, 56 subregion names that are non-unique for their countries in the data, they are listed below (region id, subregion name, number of matching Subregion objects). These represent 119 Subregion objects, withe the following ids.
|
Thank you for reporting this, I'll add that data to the tests and fix it when I can. I don't have a lot of free time at the moment. |
I also encounter the same problem. |
same here |
@blag I can help sanding the test, but about the info given by @joshourisman the info is duplicated so we have to avoid that, right? |
@mayela I think the fix for this is: diff --git a/cities/management/commands/cities.py b/cities/management/commands/cities.py
index a71b359..1972838 100644
--- a/cities/management/commands/cities.py
+++ b/cities/management/commands/cities.py
@@ -1005,6 +1005,19 @@ class Command(BaseCommand):
region__country=pc.country)
except Subregion.DoesNotExist:
pc.subregion = None
+ except Subregion.MultipleObjectsReturned:
+ self.logger.warn("Found multiple subregions for '{}' in '{}' - ignoring".format(
+ pc.region_name,
+ pc.subregion_name))
+ self.logger.debug("item: {}\nsubregions: {}".format(
+ item,
+ Subregion.objects.filter(
+ Q(region__name_std__iexact=pc.region_name) |
+ Q(region__name__iexact=pc.region_name),
+ Q(name_std__iexact=pc.subregion_name) |
+ Q(name__iexact=pc.subregion_name),
+ region__country=pc.country).values_list('id', flat=True)))
+ pc.subregion = None
else:
pc.subregion = None but I don't really have time to add it to the test data and verify it. |
works for me |
any update on getting this fixed merged into master? |
@pstreck No update yet, but I did get laid off last Friday! So I'll have some free time later this week to fix this, add the test data, and push it to PyPI. |
I've been working on this, but I'm having trouble reproducing the issue. If it's not working for you, please post your cities configuration variables from your project's I have tried commenting out the entire PYTHONPATH=. python test_project/manage.py cities --import=all from the root of the repository (Python 3.5.3, Django 2.0). All subregions seem to import successfully. If you can reproduce the issue that way, please also set PYTHONPATH=. TRAVIS_LOG_LEVEL=DEBUG python test_project/manage.py cities --import=all 2>&1 | tee everything.log and copy/paste the I'm not done wrestling with this, but I don't have as much free time as I thought I would to fix it. Any direction or further troubleshooting information you can give me will help me. Thanks! |
@blag Your code above fixed this issue for me. |
@77cc33 It "worked" in that it doesn't error out anymore, but it doesn't connect up postal codes to their subregion in that case either. |
I am facing similar issue. While importing postal codes, I am getting following error. Please find the stack trace. Importing postal codes: 23%|█▍ | 293363/1264588 [2:12:35<7:18:56, 36.88it/s]Traceback (most recent call last): File "/home/manimaran/4.0/v4/lib/python3.5/site-packages/cities/management/commands/cities.py", line 1029, in import_postal_code |
I've deployed this and hit this error. Django 2.0.7, Python 3.7 in a virtenv. I'm able to avoid this error if I only import certain countries, such as US, CA, AU. I tried UK and this failed. I've just put in the code you created higher in this thread and trying a full import but another comment suggested this doesn't link those post codes, so I'm a little worried about those. I would really appreciate if this could be fixed and data is consistent. Maybe post your full config so we can confirm what the difference in your settings are? I'm using SQLlite for testing, my settings.py
|
Same here importing cities1000.zip. Is this project dead? |
Maintainer (sort of) here. I don’t have a lot of time for this project as I once did and I could use some help. If anybody can put this in an up-to-date PR that would help (make sure you include tests, even if it’s mocking a response or a file), but long term I may need to turn over maintenance to somebody else. If anybody has time, email coderholic directly, explain a bit about who you are, include a few links to your open source contributions (especially Django apps), and ask to be made a maintainer. Please keep me on as a maintainer, as I still have an invested interest in this project and I may have more time for this project in the future. |
Added workaround from here: coderholic#180 (comment)
@blag |
The topic issue still happens.
|
The same issue CITIES_LOCALES = ['LANGUAGES'] |
Someone manage to make this work? |
The same issue |
Same here for Districts when import of postal_codes starts.
(django 3.1.2, python 3.8) |
Checklist
master
branch of django-cities.Steps to reproduce
python project/manage.py cities --import=all
Expected behavior
Sucessful import
Actual behavior
The text was updated successfully, but these errors were encountered: