diff --git a/CHANGES.rst b/CHANGES.rst index fc13bfbb..1683704e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,6 +6,11 @@ Async PRAW follows `semantic versioning `_. Unreleased ---------- +**Fixed** + +- Fixed an issue where some :class:`.RedditBase` objects would be sent in a request as + ``"None"``. + 7.3.0 (2021/06/18) ------------------ diff --git a/asyncpraw/models/reddit/base.py b/asyncpraw/models/reddit/base.py index 06bb312b..ac818a39 100644 --- a/asyncpraw/models/reddit/base.py +++ b/asyncpraw/models/reddit/base.py @@ -1,5 +1,4 @@ """Provide the RedditBase class.""" -from copy import deepcopy from typing import TYPE_CHECKING, Any, Dict, Optional, Union from urllib.parse import urlparse @@ -13,13 +12,6 @@ class RedditBase(AsyncPRAWBase): """Base class that represents actual Reddit objects.""" - def __deepcopy__(self, memodict={}): - """Skip copying ``_reddit`` attribute when preforming a deep copy.""" - return type(self)( - self._reddit, - _data=deepcopy({k: v for k, v in self.__dict__.items() if k != "_reddit"}), - ) - @staticmethod def _url_parts(url): parsed = urlparse(url) diff --git a/asyncpraw/models/reddit/submission.py b/asyncpraw/models/reddit/submission.py index aa941037..409736cf 100644 --- a/asyncpraw/models/reddit/submission.py +++ b/asyncpraw/models/reddit/submission.py @@ -213,7 +213,7 @@ async def set_original_content(self): "fullname": self.thing.fullname, "should_set_oc": True, "executed": False, - "r": str(self.thing.subreddit), + "r": self.thing.subreddit, } await self.thing._reddit.post(API_PATH["set_original_content"], data=data) @@ -333,7 +333,7 @@ async def unset_original_content(self): "fullname": self.thing.fullname, "should_set_oc": False, "executed": False, - "r": str(self.thing.subreddit), + "r": self.thing.subreddit, } await self.thing._reddit.post(API_PATH["set_original_content"], data=data) diff --git a/asyncpraw/models/reddit/subreddit.py b/asyncpraw/models/reddit/subreddit.py index c48a28c7..1545b999 100644 --- a/asyncpraw/models/reddit/subreddit.py +++ b/asyncpraw/models/reddit/subreddit.py @@ -1697,7 +1697,7 @@ def __call__( print(flair) """ - Subreddit._safely_add_arguments(generator_kwargs, "params", name=str(redditor)) + Subreddit._safely_add_arguments(generator_kwargs, "params", name=redditor) generator_kwargs.setdefault("limit", None) url = API_PATH["flairlist"].format(subreddit=self.subreddit) return ListingGenerator(self.subreddit._reddit, url, **generator_kwargs) @@ -2903,7 +2903,7 @@ async def opt_in(self): print(submission) # Returns Submission """ - data = {"sr_name": str(self.subreddit)} + data = {"sr_name": self.subreddit} try: await self.subreddit._reddit.post(API_PATH["quarantine_opt_in"], data=data) except Redirect: @@ -2925,7 +2925,7 @@ async def opt_out(self): print(submission) """ - data = {"sr_name": str(self.subreddit)} + data = {"sr_name": self.subreddit} try: await self.subreddit._reddit.post(API_PATH["quarantine_opt_out"], data=data) except Redirect: @@ -3499,9 +3499,9 @@ async def create( data = { "body": body, "isAuthorHidden": author_hidden, - "srName": str(self.subreddit), + "srName": self.subreddit, "subject": subject, - "to": str(recipient), + "to": recipient, } return await self.subreddit._reddit.post( API_PATH["modmail_conversations"], data=data diff --git a/tests/integration/cassettes/TestSubredditFlair.test__call.json b/tests/integration/cassettes/TestSubredditFlair.test__call.json index a77b81c3..569aef49 100644 --- a/tests/integration/cassettes/TestSubredditFlair.test__call.json +++ b/tests/integration/cassettes/TestSubredditFlair.test__call.json @@ -5,11 +5,15 @@ "body": [ [ "grant_type", - "refresh_token" + "password" ], [ - "refresh_token", - "" + "password", + "" + ], + [ + "username", + "" ] ], "headers": { @@ -23,7 +27,7 @@ "close" ], "User-Agent": [ - " Async PRAW/7.1.1.dev0 asyncprawcore/1.4.0.post1" + " Async PRAW/7.3.1.dev0 asyncprawcore/2.2.0" ] }, "method": "POST", @@ -31,26 +35,26 @@ }, "response": { "body": { - "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"account creddits edit flair history identity livemanage modconfig modcontributors modflair modlog modmail modothers modposts modself modtraffic modwiki mysubreddits privatemessages read report save structuredstyles submit subscribe vote wikiedit wikiread\"}" + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}" }, "headers": { "Accept-Ranges": "bytes", "Cache-Control": "max-age=0, must-revalidate", "Connection": "close", - "Content-Length": "367", + "Content-Length": "121", "Content-Type": "application/json; charset=UTF-8", - "Date": "Sat, 11 Jul 2020 04:06:42 GMT", + "Date": "Tue, 06 Jul 2021 20:00:27 GMT", "Server": "snooserv", - "Set-Cookie": "edgebucket=fgopez0X5Oe6uN6Z9r; Domain=reddit.com; Max-Age=63071999; Path=/; secure", + "Set-Cookie": "edgebucket=H5RxIpRbXgkx2oOMGi; Domain=reddit.com; Max-Age=63071999; Path=/; secure", "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", + "X-Clacks-Overhead": "GNU Terry Pratchett", "X-Moose": "majestic", - "X-Served-By": "cache-mci5927-MCI", - "X-Timer": "S1594440402.372684,VS0,VE91", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", + "x-ratelimit-remaining": "299", + "x-ratelimit-reset": "573", + "x-ratelimit-used": "1", "x-xss-protection": "1; mode=block" }, "status": { @@ -71,38 +75,35 @@ "bearer " ], "User-Agent": [ - " Async PRAW/7.1.1.dev0 asyncprawcore/1.4.0.post1" + " Async PRAW/7.3.1.dev0 asyncprawcore/2.2.0" ] }, "method": "GET", - "uri": "https://oauth.reddit.com/r//api/flairlist/?name=None&limit=1024&raw_json=1" + "uri": "https://oauth.reddit.com/r//api/flairlist/?limit=1024&raw_json=1" }, "response": { "body": { - "string": "{\"users\": [{\"flair_css_class\": null, \"user\": \"None\", \"flair_text\": null}]}" + "string": "{\"users\": [{\"flair_css_class\": \"async default\", \"user\": \"spez\", \"flair_text\": null}, {\"flair_css_class\": \"async default\", \"user\": \"bsimpson\", \"flair_text\": null}, {\"flair_css_class\": \"async default\", \"user\": \"spladug\", \"flair_text\": \"a,b\"}, {\"flair_css_class\": \"testing\", \"user\": \"\", \"flair_text\": \"\\\"testing\\\"\"}, {\"flair_css_class\": \"myCSS\", \"user\": \"Lil_SpazTest\", \"flair_text\": \"redditor flair\"}]}" }, "headers": { "Accept-Ranges": "bytes", "Cache-Control": "private, s-maxage=0, max-age=0, must-revalidate, no-store, max-age=0, must-revalidate", "Connection": "keep-alive", - "Content-Length": "74", + "Content-Length": "411", "Content-Type": "application/json; charset=UTF-8", - "Date": "Sat, 11 Jul 2020 04:06:42 GMT", + "Date": "Tue, 06 Jul 2021 20:00:28 GMT", "Expires": "-1", "Server": "snooserv", "Set-Cookie": "csv=1; Max-Age=63072000; Domain=.reddit.com; Path=/; Secure; SameSite=None", "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", + "X-Clacks-Overhead": "GNU Terry Pratchett", "X-Moose": "majestic", - "X-Served-By": "cache-mci5931-MCI", - "X-Timer": "S1594440403.550532,VS0,VE117", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", - "x-ratelimit-remaining": "224.0", - "x-ratelimit-reset": "198", - "x-ratelimit-used": "376", + "x-ratelimit-remaining": "599.0", + "x-ratelimit-reset": "572", + "x-ratelimit-used": "1", "x-ua-compatible": "IE=edge", "x-xss-protection": "1; mode=block" }, @@ -110,10 +111,10 @@ "code": 200, "message": "OK" }, - "url": "https://oauth.reddit.com/r//api/flairlist/?name=None&limit=1024&raw_json=1" + "url": "https://oauth.reddit.com/r//api/flairlist/?limit=1024&raw_json=1" } } ], - "recorded_at": "2020-07-10T23:06:42", + "recorded_at": "2021-07-06T15:00:28", "version": 1 } diff --git a/tests/integration/cassettes/TestSubredditFlair.test_delete_all.json b/tests/integration/cassettes/TestSubredditFlair.test_delete_all.json index 0d8d7aa5..1c79b2f6 100644 --- a/tests/integration/cassettes/TestSubredditFlair.test_delete_all.json +++ b/tests/integration/cassettes/TestSubredditFlair.test_delete_all.json @@ -5,11 +5,15 @@ "body": [ [ "grant_type", - "refresh_token" + "password" ], [ - "refresh_token", - "" + "password", + "" + ], + [ + "username", + "" ] ], "headers": { @@ -23,7 +27,7 @@ "close" ], "User-Agent": [ - " Async PRAW/7.1.1.dev0 asyncprawcore/1.4.0.post1" + " Async PRAW/7.3.1.dev0 asyncprawcore/2.2.0" ] }, "method": "POST", @@ -31,26 +35,26 @@ }, "response": { "body": { - "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"account creddits edit flair history identity livemanage modconfig modcontributors modflair modlog modmail modothers modposts modself modtraffic modwiki mysubreddits privatemessages read report save structuredstyles submit subscribe vote wikiedit wikiread\"}" + "string": "{\"access_token\": \"\", \"token_type\": \"bearer\", \"expires_in\": 3600, \"scope\": \"*\"}" }, "headers": { "Accept-Ranges": "bytes", "Cache-Control": "max-age=0, must-revalidate", "Connection": "close", - "Content-Length": "367", + "Content-Length": "121", "Content-Type": "application/json; charset=UTF-8", - "Date": "Sat, 11 Jul 2020 04:09:55 GMT", + "Date": "Tue, 06 Jul 2021 20:01:25 GMT", "Server": "snooserv", - "Set-Cookie": "edgebucket=9BYfrxkQAkqZRVIxem; Domain=reddit.com; Max-Age=63071999; Path=/; secure", + "Set-Cookie": "edgebucket=LczBZYmm5uITITO3r5; Domain=reddit.com; Max-Age=63071999; Path=/; secure", "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", + "X-Clacks-Overhead": "GNU Terry Pratchett", "X-Moose": "majestic", - "X-Served-By": "cache-mci5923-MCI", - "X-Timer": "S1594440596.645558,VS0,VE118", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", + "x-ratelimit-remaining": "298", + "x-ratelimit-reset": "515", + "x-ratelimit-used": "2", "x-xss-protection": "1; mode=block" }, "status": { @@ -71,38 +75,35 @@ "bearer " ], "User-Agent": [ - " Async PRAW/7.1.1.dev0 asyncprawcore/1.4.0.post1" + " Async PRAW/7.3.1.dev0 asyncprawcore/2.2.0" ] }, "method": "GET", - "uri": "https://oauth.reddit.com/r//api/flairlist/?name=None&limit=1024&raw_json=1" + "uri": "https://oauth.reddit.com/r//api/flairlist/?limit=1024&raw_json=1" }, "response": { "body": { - "string": "{\"users\": [{\"flair_css_class\": null, \"user\": \"None\", \"flair_text\": null}]}" + "string": "{\"users\": [{\"flair_css_class\": \"async default\", \"user\": \"spez\", \"flair_text\": null}, {\"flair_css_class\": \"async default\", \"user\": \"bsimpson\", \"flair_text\": null}, {\"flair_css_class\": \"async default\", \"user\": \"spladug\", \"flair_text\": \"a,b\"}, {\"flair_css_class\": \"testing\", \"user\": \"\", \"flair_text\": \"\\\"testing\\\"\"}, {\"flair_css_class\": \"myCSS\", \"user\": \"Lil_SpazTest\", \"flair_text\": \"redditor flair\"}]}" }, "headers": { "Accept-Ranges": "bytes", "Cache-Control": "private, s-maxage=0, max-age=0, must-revalidate, no-store, max-age=0, must-revalidate", "Connection": "keep-alive", - "Content-Length": "74", + "Content-Length": "411", "Content-Type": "application/json; charset=UTF-8", - "Date": "Sat, 11 Jul 2020 04:09:55 GMT", + "Date": "Tue, 06 Jul 2021 20:01:25 GMT", "Expires": "-1", "Server": "snooserv", "Set-Cookie": "csv=1; Max-Age=63072000; Domain=.reddit.com; Path=/; Secure; SameSite=None", "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", + "X-Clacks-Overhead": "GNU Terry Pratchett", "X-Moose": "majestic", - "X-Served-By": "cache-mci5944-MCI", - "X-Timer": "S1594440596.836795,VS0,VE103", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", - "x-ratelimit-remaining": "10.0", - "x-ratelimit-reset": "5", - "x-ratelimit-used": "590", + "x-ratelimit-remaining": "598.0", + "x-ratelimit-reset": "515", + "x-ratelimit-used": "2", "x-ua-compatible": "IE=edge", "x-xss-protection": "1; mode=block" }, @@ -110,14 +111,21 @@ "code": 200, "message": "OK" }, - "url": "https://oauth.reddit.com/r//api/flairlist/?name=None&limit=1024&raw_json=1" + "url": "https://oauth.reddit.com/r//api/flairlist/?limit=1024&raw_json=1" } }, { "request": { - "body": { - "flair_csv": "None,," - }, + "body": [ + [ + "api_type", + "json" + ], + [ + "flair_csv", + "spez,,\nbsimpson,,\nspladug,,\n,,\nLil_SpazTest,," + ] + ], "headers": { "Accept-Encoding": [ "identity" @@ -126,7 +134,7 @@ "bearer " ], "User-Agent": [ - " Async PRAW/7.1.1.dev0 asyncprawcore/1.4.0.post1" + " Async PRAW/7.3.1.dev0 asyncprawcore/2.2.0" ] }, "method": "POST", @@ -134,30 +142,27 @@ }, "response": { "body": { - "string": "[{\"status\": \"removed flair for user None\", \"errors\": {}, \"ok\": true, \"warnings\": {}}]" + "string": "[{\"status\": \"removed flair for user spez\", \"errors\": {}, \"ok\": true, \"warnings\": {}}, {\"status\": \"removed flair for user bsimpson\", \"errors\": {}, \"ok\": true, \"warnings\": {}}, {\"status\": \"removed flair for user spladug\", \"errors\": {}, \"ok\": true, \"warnings\": {}}, {\"status\": \"removed flair for user \", \"errors\": {}, \"ok\": true, \"warnings\": {}}, {\"status\": \"removed flair for user Lil_SpazTest\", \"errors\": {}, \"ok\": true, \"warnings\": {}}]" }, "headers": { "Accept-Ranges": "bytes", "Cache-Control": "private, s-maxage=0, max-age=0, must-revalidate, no-store, max-age=0, must-revalidate", "Connection": "keep-alive", - "Content-Length": "85", + "Content-Length": "447", "Content-Type": "application/json; charset=UTF-8", - "Date": "Sat, 11 Jul 2020 04:09:56 GMT", + "Date": "Tue, 06 Jul 2021 20:01:26 GMT", "Expires": "-1", "Server": "snooserv", - "Set-Cookie": "session_tracker=llglehikgmkmmgonlc.0.1594440596014.Z0FBQUFBQmZDVHVVUE5HN0RmcDhObzFPLS1hOWwtRllCY0NpRkJxZFN3YzhxclFrMnlSSG1HQ09ieUVpNDVybllQYWwxVGdvVkxqSGxfSFhCbUt2V0cxVjF2RDRRc1RPRU5NTlVET2hwWjdBczBnNjM1aVhuQ0hTZkxiVWR6LUFKVkUxUmY2VnYyWkY; Domain=reddit.com; Max-Age=7199; Path=/; expires=Sat, 11-Jul-2020 06:09:56 GMT; secure", + "Set-Cookie": "session_tracker=iriqfrcndboeiolqkn.0.1625601685900.Z0FBQUFBQmc1TGFXRjJic1hzSlg5dnZ5c3JXc3pBQzZSQW5nLUV2Y21IeVJ5bUxWY2Zmc3RZZHlZRG1yeUJaRmJ0M25mSWZ0eDRjeWpqczJDUDRHUmFlTEg5Y1A3bkJhMlBqSXVNMElsQnBwQzBzd29oeE1kd24wZ1NidzVMOHh2ZURhVlhXdm9KVjg; Domain=reddit.com; Max-Age=7199; Path=/; expires=Tue, 06-Jul-2021 22:01:26 GMT; secure", "Strict-Transport-Security": "max-age=15552000; includeSubDomains; preload", "Via": "1.1 varnish", - "X-Cache": "MISS", - "X-Cache-Hits": "0", + "X-Clacks-Overhead": "GNU Terry Pratchett", "X-Moose": "majestic", - "X-Served-By": "cache-mci5944-MCI", - "X-Timer": "S1594440596.958527,VS0,VE342", "x-content-type-options": "nosniff", "x-frame-options": "SAMEORIGIN", - "x-ratelimit-remaining": "9.0", - "x-ratelimit-reset": "4", - "x-ratelimit-used": "591", + "x-ratelimit-remaining": "597.0", + "x-ratelimit-reset": "515", + "x-ratelimit-used": "3", "x-ua-compatible": "IE=edge", "x-xss-protection": "1; mode=block" }, @@ -169,6 +174,6 @@ } } ], - "recorded_at": "2020-07-10T23:09:56", + "recorded_at": "2021-07-06T15:01:26", "version": 1 } diff --git a/tests/integration/models/reddit/test_subreddit.py b/tests/integration/models/reddit/test_subreddit.py index 0334aa10..f9e3a619 100644 --- a/tests/integration/models/reddit/test_subreddit.py +++ b/tests/integration/models/reddit/test_subreddit.py @@ -994,7 +994,7 @@ async def test_delete_all(self, _): with self.use_cassette(): subreddit = await self.reddit.subreddit(pytest.placeholders.test_subreddit) response = await subreddit.flair.delete_all() - assert len(response) == 1 + assert len(response) == 5 assert all("removed" in x["status"] for x in response) async def test_set__flair_id(self):