Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

oauth2client: django_orm.Storage locked_put should try a get/update first #528

Closed
wizravi opened this issue Jun 24, 2016 · 5 comments
Closed

Comments

@wizravi
Copy link

wizravi commented Jun 24, 2016

This issue was originally reported at : bradleybossard/google-api-python-client#278, But which look to be oauth2client issue.

Issue:

As described in the above link,
I also faced the problem where refresh was throws an IntegrityError
due to violation of the unique constrain in model.
Following change worked for me:
In oauth2client/client.py, inside "def _do_refresh_request", I changed the line self.store.locked_put(self) (in line#937) to self.store.locked_put(self, overwrite=True).
Can anyone comment if it is safe fix.

@theacodes
Copy link
Contributor

@waprin can you take a look at this?

@waprin
Copy link
Contributor

waprin commented Jun 24, 2016

yes

@waprin
Copy link
Contributor

waprin commented Jun 24, 2016

@wizravi I am literally in the middle of rewriting that whole class so this is good information to be aware of. I have a rough sketch here: https://github.com/waprin/oauth2client/pull/4/files though I don't think I address the issue you're describing. If you don't mind, I can put you on the review when I submit a PR ot the main repo sometime soon (next week-ish).

@letsmakesense
Copy link

+1 for changing to overwrite=True

Everyone following the docs will have the same issue because if user is the primary key for the credentials model you can't insert two credentials for the same user.

To me it seems that 'get_or_create()' (the overwrite=True case) is always the right choice in this scenario.

@waprin
Copy link
Contributor

waprin commented Jul 12, 2016

Agreed, I am finishing up a PR for this, just fixing tests etc. Will mention you on it.

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

No branches or pull requests

3 participants