Repository: python-social-auth/social-core
Pull request #1020 (2025-02-13 18:50:05)

fix: revert API changes from #986
## Proposed changes

This was a breaking change in API that social-app-django and other storages rely on.

<!--
Describe the big picture of your changes here to communicate to the maintainers
why we should accept this pull request. If it fixes a bug or resolves a feature
request, be sure to link to that issue.
-->

## Checklist

_Put an `x` in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask. We're here to
help! This is simply a reminder of what we are going to look for before merging
your code._

- [ ] Lint and unit tests pass locally with my changes
- [ ] I have added tests that prove my fix is effective or that my feature works
- [ ] I have added documentation to https://github.com/python-social-auth/social-docs

## Other information

Any other information that is important to this PR such as screenshots of how
the component looks before and after the change.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/python-social-auth/social-core/pull/1020?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 78.15%. Comparing base [(`326d4b3`)](https://app.codecov.io/gh/python-social-auth/social-core/commit/326d4b3c4aa69e92c19b472b437dd718c5ee5bd8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth) to head [(`f8391a7`)](https://app.codecov.io/gh/python-social-auth/social-core/commit/f8391a7a4d916b96d5ff7923f591a805f90835ce?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth).
> Report is 83 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1020      +/-   ##
==========================================
+ Coverage   77.88%   78.15%   +0.26%     
==========================================
  Files         347      348       +1     
  Lines       10669    10765      +96     
  Branches      504      457      -47     
==========================================
+ Hits         8310     8413     +103     
+ Misses       2200     2192       -8     
- Partials      159      160       +1     
```

| [Flag](https://app.codecov.io/gh/python-social-auth/social-core/pull/1020/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth) | Coverage Δ | |
|---|---|---|
| [unittests](https://app.codecov.io/gh/python-social-auth/social-core/pull/1020/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth) | `78.15% <100.00%> (+0.26%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/python-social-auth/social-core/pull/1020?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-social-auth).


Patch:
diff --git a/social_core/backends/discourse.py b/social_core/backends/discourse.py
index 8ebe99e2..398e1a74 100644
--- a/social_core/backends/discourse.py
+++ b/social_core/backends/discourse.py
@@ -52,8 +52,8 @@ class DiscourseAuth(BaseAuth):
     def add_nonce(self, nonce):
         self.strategy.storage.nonce.use(self.setting("SERVER_URL"), time.time(), nonce)
 
-    def get_nonce(self, nonce):
-        return self.strategy.storage.nonce.get_nonce(self.setting("SERVER_URL"), nonce)
+    def get(self, nonce):
+        return self.strategy.storage.nonce.get(self.setting("SERVER_URL"), nonce)
 
     def delete_nonce(self, nonce):
         self.strategy.storage.nonce.delete(nonce)
@@ -79,7 +79,7 @@ class DiscourseAuth(BaseAuth):
 
         # Validate the nonce to ensure the request was not modified
         response = parse_qs(decoded_params)
-        nonce_obj = self.get_nonce(response.get("nonce"))
+        nonce_obj = self.get(response.get("nonce"))
         if nonce_obj:
             self.delete_nonce(nonce_obj)
         else:
diff --git a/social_core/backends/open_id_connect.py b/social_core/backends/open_id_connect.py
index 3c9108a1..b7ee429a 100644
--- a/social_core/backends/open_id_connect.py
+++ b/social_core/backends/open_id_connect.py
@@ -139,9 +139,9 @@ class OpenIdConnectAuth(BaseOAuth2):
         self.strategy.storage.association.store(url, association)
         return nonce
 
-    def get_nonce(self, nonce):
+    def get(self, nonce):
         try:
-            return self.strategy.storage.association.get_association(
+            return self.strategy.storage.association.get(
                 server_url=self.authorization_url(), handle=nonce
             )[0]
         except IndexError:
@@ -166,7 +166,7 @@ class OpenIdConnectAuth(BaseOAuth2):
         if not nonce:
             raise AuthTokenError(self, "Incorrect id_token: nonce")
 
-        nonce_obj = self.get_nonce(nonce)
+        nonce_obj = self.get(nonce)
         if nonce_obj:
             self.remove_nonce(nonce_obj.id)
         else:
diff --git a/social_core/storage.py b/social_core/storage.py
index 979acab3..57f583f6 100644
--- a/social_core/storage.py
+++ b/social_core/storage.py
@@ -1,5 +1,7 @@
 """Models mixins for Social Auth"""
 
+from __future__ import annotations
+
 import base64
 import re
 import uuid
@@ -198,7 +200,7 @@ class NonceMixin:
         raise NotImplementedError("Implement in subclass")
 
     @classmethod
-    def get_nonce(cls, server_url, salt):
+    def get(cls, server_url, salt):
         """Retrieve a Nonce instance"""
         raise NotImplementedError("Implement in subclass")
 
@@ -224,10 +226,7 @@ class AssociationMixin:
         if handle is not None:
             kwargs["handle"] = handle
         return sorted(
-            (
-                (assoc.id, cls.openid_association(assoc))
-                for assoc in cls.get_association(**kwargs)
-            ),
+            ((assoc.id, cls.openid_association(assoc)) for assoc in cls.get(**kwargs)),
             key=lambda x: x[1].issued,
             reverse=True,
         )
@@ -251,7 +250,7 @@ class AssociationMixin:
         raise NotImplementedError("Implement in subclass")
 
     @classmethod
-    def get_association(cls, *args, **kwargs):
+    def get(cls, server_url: str | None = None, handle: str | None = None):
         """Get an Association instance"""
         raise NotImplementedError("Implement in subclass")
 


Test patch:
diff --git a/social_core/tests/models.py b/social_core/tests/models.py
index 2d05bc12..f3e8ddb3 100644
--- a/social_core/tests/models.py
+++ b/social_core/tests/models.py
@@ -169,7 +169,9 @@ class TestNonce(NonceMixin, BaseModel):
         return nonce
 
     @classmethod
-    def get_nonce(cls, server_url, salt):
+    def get(  # type: ignore[override]
+        cls, server_url, salt
+    ):
         return TestNonce.cache[server_url]
 
     @classmethod
@@ -204,10 +206,10 @@ class TestAssociation(AssociationMixin, BaseModel):
         assoc.save()
 
     @classmethod
-    def get_association(
+    def get(  # type: ignore[override]
         cls: type[TestAssociation],
-        server_url=None,
-        handle=None,
+        server_url: str | None = None,
+        handle: str | None = None,
     ) -> list[AssociationMixin]:
         result = []
         for assoc in TestAssociation.cache.values():
diff --git a/social_core/tests/test_storage.py b/social_core/tests/test_storage.py
index e4f4ece7..3e328d04 100644
--- a/social_core/tests/test_storage.py
+++ b/social_core/tests/test_storage.py
@@ -90,7 +90,7 @@ class BrokenAssociationTests(unittest.TestCase):
 
     def test_get(self):
         with self.assertRaisesRegex(NotImplementedError, NOT_IMPLEMENTED_MSG):
-            self.association.get_association()
+            self.association.get()
 
     def test_remove(self):
         with self.assertRaisesRegex(NotImplementedError, NOT_IMPLEMENTED_MSG):