django-cities returns a MultipleObjectsReturned exception raised while importing
See original GitHub issueIssue Description
Checklist
- I have verified that I am using a GIS-enabled database, such as PostGIS or Spatialite.
- I have verified that that issue exists against the
master
branch of django-cities. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
python project/manage.py cities --import=all
Expected behavior
Sucessful import
Actual behavior
Traceback (most recent call last):
File "project/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/usr/lib/python3.4/contextlib.py", line 30, in inner
return func(*args, **kwds)
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/cities/management/commands/cities.py", line 160, in handle
func()
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/cities/management/commands/cities.py", line 1005, in import_postal_code
region__country=pc.country)
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/vagrant/environment/venv/lib/python3.4/site-packages/django/db/models/query.py", line 384, in get
(self.model._meta.object_name, num)
cities.models.MultipleObjectsReturned: get() returned more than one Subregion -- it returned 2!
Issue Analytics
- State:
- Created 5 years ago
- Comments:22
Top Results From Across the Web
how to catch the MultipleObjectsReturned error in django
Use a filter: Location.objects.filter(name='Paul').first(). Or import the exception: from django.core.exceptions import ...
Read more >django-cities - Bountysource
The situation around importing the data is very frustrating. ... django-cities returns a MultipleObjectsReturned exception raised while importing $ 0.
Read more >Django Exceptions — Django v1.3.1 documentation
The MultipleObjectsReturned exception is raised by a query if only one object is expected, but multiple objects are returned.
Read more >Model class reference — Django 4.1.4 documentation
This exception is raised by the ORM when an expected object is not found. ... Django provides a MultipleObjectsReturned exception as an attribute...
Read more >Making queries | Django documentation
from datetime import date from django.db import models class Blog(models. ... The all() method returns a QuerySet of all the objects in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The topic issue still happens.
@mayela I think the fix for this is:
but I don’t really have time to add it to the test data and verify it.