Skip to content
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

Multiple objects return from get() query #48

Open
slezica opened this issue Dec 5, 2012 · 4 comments
Open

Multiple objects return from get() query #48

slezica opened this issue Dec 5, 2012 · 4 comments
Assignees

Comments

@slezica
Copy link

slezica commented Dec 5, 2012

NOTE: the following error arises in a slightly modified implementation, so I can't guarantee it exists
in this codebase, and does not stop the application from sending the e-mails.

Stack trace:

File "/app/.heroku/venv/lib/python2.7/site-packages/sendgrid/message.py", line 121, in send
    sendgrid_email_sent.send(sender=self, message=self, response=response)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/app/.heroku/venv/lib/python2.7/site-packages/sendgrid/models.py", line 109, in save_email_message
    argument, argumentCreated = Argument.objects.get_or_create(key=k)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/models/manager.py", line 134, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/models/query.py", line 442, in get_or_create
    return self.get(**lookup), False
  File "/app/.heroku/venv/lib/python2.7/site-packages/django/db/models/query.py", line 368, in get
    % (self.model._meta.object_name, num, kwargs))
MultipleObjectsReturned: get() returned more than one Argument -- it returned 2! Lookup parameters were {'key': 'message_id'}

I'll make time to dig up the relevant database rows and, if I find it's not my fault, post minimal code to reproduce the issue.

@RyanBalfanz
Copy link
Owner

Looks like you have multiple sendgrid.models.Arguments (https://github.com/RyanBalfanz/django-sendgrid/blob/develop/sendgrid/models.py#L157) of the same key.

There should probably be a unique=True on Argument.key but there is not in the current release. I'd like to better understand how multiple Arguments of that key were created in the first place before adding that constraint in a later release.

FWIW, I've sent well over a million emails and haven't exhibited this behavior, which makes me think it's probably okay to add that constraint. However, in your case the migration should fail unless you manually migrate your data.

@ghost ghost assigned RyanBalfanz Dec 5, 2012
RyanBalfanz added a commit that referenced this issue Dec 6, 2012
Note: This still needs a migration
RyanBalfanz added a commit that referenced this issue Dec 6, 2012
@RyanBalfanz
Copy link
Owner

@slezica I quickly threw together a tool to help with the data migration (see 904f214)

@slezica
Copy link
Author

slezica commented Dec 12, 2012

Wow, swift action! Thanks a lot, Ryan!

@RyanBalfanz
Copy link
Owner

Thank @hoddez and myself once it's released ;)
We're still doing some testing and such…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants