NicholasTurner23 / analyticreports

0 stars 5 forks source link

Multiple contacts #9

Closed faithNassiwa closed 7 years ago

faithNassiwa commented 7 years ago
Traceback (most recent call last):
  File "manage.py", line 24, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/faith/.virtualenvs/analyticreport/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
    utility.execute()
  File "/Users/faith/.virtualenvs/analyticreport/lib/python2.7/site-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/faith/.virtualenvs/analyticreport/lib/python2.7/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/faith/.virtualenvs/analyticreport/lib/python2.7/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/faith/Documents/tmcg_assignments/analyticreports/reports/management/commands/update_workspaces.py", line 7, in handle
    Workspace.get_rapidpro_workspaces()
  File "/Users/faith/Documents/tmcg_assignments/analyticreports/reports/models.py", line 35, in get_rapidpro_workspaces
    Message.save_messages(client=client)
  File "/Users/faith/Documents/tmcg_assignments/analyticreports/reports/models.py", line 358, in save_messages
    contact = Contact.objects.get(uuid=message.contact.uuid)
  File "/Users/faith/.virtualenvs/analyticreport/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/faith/.virtualenvs/analyticreport/lib/python2.7/site-packages/django/db/models/query.py", line 384, in get
    (self.model._meta.object_name, num)
reports.models.MultipleObjectsReturned: get() returned more than one Contact -- it returned 4!
faithNassiwa commented 7 years ago

Temporal Fix: Use filter and get first existence instead of plain get. contact = Contact.objects.filter(uuid=message.contact.uuid).first()

NicholasTurner23 commented 7 years ago

I think we have different code. I don't have "contact = Contact.objects.get(uuid=message.contact.uuid)" anywhere in my code.

faithNassiwa commented 7 years ago

Its in the Contact Model, review the save_contact method. It does not make sense why they would exist more than one but for some reason not known to me as of now it seems their are these occurrences as per the error returned. The above done is a temporal fix as we should not have more than one occurrence and need to figure out what is causing it.

NicholasTurner23 commented 7 years ago

That error is from the save the save_message method. "in save_messages contact = Contact.objects.get(uuid=message.contact.uuid)" I do not see how it is attached to the save_contact method. Aren't uuid unique?

faithNassiwa commented 7 years ago

Sorry, actually its missing you your code base. Lets conclude this tomorrow.