Issue #19 open

MultipleObjectsReturned: get() returned more than one Address -- it returned 2! Lookup parameters...

rasca7
created an issue

Hi! I've had this issue twice in production, it think it's due to the use of get_or_create and the lack of a unique constraint in the address field.

Here's the traceback:

MultipleObjectsReturned: get() returned more than one Address -- it returned 2! Lookup parameters were {'address': u'Belgrano 1600, Montserrat'}

Stacktrace (most recent call last):

  File "django/core/handlers/base.py", line 100, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "menus/utils.py", line 220, in _wrapped
    return func(request, *args, **kwargs)
  File "properties/views.py", line 90, in sale_details
    { 'prop': prop , 'from_page':from_page}, context_instance=RequestContext(request))
  File "django/shortcuts/__init__.py", line 20, in render_to_response
    return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
  File "django/template/loader.py", line 186, in render_to_string
    return t.render(context_instance)
  File "django/template/__init__.py", line 173, in render
    return self._render(context)
  File "django/template/__init__.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/template/loader_tags.py", line 125, in render
    return compiled_parent._render(context)
  File "django/template/__init__.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/template/loader_tags.py", line 125, in render
    return compiled_parent._render(context)
  File "django/template/__init__.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/template/loader_tags.py", line 125, in render
    return compiled_parent._render(context)
  File "django/template/__init__.py", line 167, in _render
    return self.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "django/templatetags/cache.py", line 31, in render
    value = self.nodelist.render(context)
  File "django/template/__init__.py", line 796, in render
    bits.append(self.render_node(node, context))
  File "django/template/__init__.py", line 809, in render_node
    return node.render(context)
  File "easy_maps/templatetags/easy_maps_tags.py", line 48, in render
    map, _ = Address.objects.get_or_create(address=address or '')
  File "django/db/models/manager.py", line 135, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "django/db/models/query.py", line 376, in get_or_create
    return self.get(**lookup), False
  File "django/db/models/query.py", line 349, in get
    % (self.model._meta.object_name, num, kwargs))

Comments (8)

  1. Mikhail Korobov repo owner
    • changed status to open

    Migrations fail for me with SQLite, django 1.5 and south 0.7.6:

    Running migrations for easy_maps:
     - Migrating forwards to 0005_auto__add_unique_address_address.
     > easy_maps:0001_initial
     > easy_maps:0002_auto__add_field_address_longitude
     > easy_maps:0003_move_longitude_data
     - Migration 'easy_maps:0003_move_longitude_data' is marked for no-dry-run.
     > easy_maps:0004_auto__del_field_address_longtitude
     > easy_maps:0005_auto__add_unique_address_address
    FATAL ERROR - The following SQL query failed: DROP INDEX "easy_maps_address_884d9804"
    The error was: no such index: easy_maps_address_884d9804
     ! Error found during real run of migration! Aborting.
    
     ! Since you have a database that does not support running
     ! schema-altering statements in transactions, we have had 
     ! to leave it in an interim state between migrations.
    
    ! You *might* be able to recover with:   = CREATE INDEX "easy_maps_address_884d9804" ON "easy_maps_address" ("address"); []
    
     ! The South developers regret this has happened, and would
     ! like to gently persuade you to consider a slightly
     ! easier-to-deal-with DBMS (one that supports DDL transactions)
     ! NOTE: The error which caused the migration to fail is further up.
    Error in migration: easy_maps:0005_auto__add_unique_address_address
    

    What database/django/south are you using? Does ./manage.py migrationcheck easy_maps work for you?

  2. dmeschiari

    Migrations fail with django-easy-maps 0.8.2, MySQL, Django 1.5.1, South 0.8.1

    Running migrations for easy_maps:
     - Migrating forwards to 0005_auto__add_unique_address_address.
     > easy_maps:0001_initial
     > easy_maps:0002_auto__add_field_address_longitude
     > easy_maps:0003_move_longitude_data
     - Migration 'easy_maps:0003_move_longitude_data' is marked for no-dry-run.
     > easy_maps:0004_auto__del_field_address_longtitude
     > easy_maps:0005_auto__add_unique_address_address
    FATAL ERROR - The following SQL query failed: DROP INDEX `easy_maps_address_884d9804` ON `easy_maps_address`
    The error was: (1091, "Can't DROP 'easy_maps_address_884d9804'; check that column/key exists")
     ! Error found during real run of migration! Aborting.
    
     ! Since you have a database that does not support running
     ! schema-altering statements in transactions, we have had
     ! to leave it in an interim state between migrations.
    
    ! You *might* be able to recover with:   - no dry run output for delete_unique_column() due to dynamic DDL, sorry
       = CREATE INDEX `easy_maps_address_884d9804` ON `easy_maps_address` (`address`); []
    
     ! The South developers regret this has happened, and would
     ! like to gently persuade you to consider a slightly
     ! easier-to-deal-with DBMS (one that supports DDL transactions)
     ! NOTE: The error which caused the migration to fail is further up.
    Error in migration: easy_maps:0005_auto__add_unique_address_address
    DatabaseError: (1091, "Can't DROP 'easy_maps_address_884d9804'; check that column/key exists")
    
  3. Log in to comment