Fixed #36830 -- Stored the cache alias on cache backend instances. - #20469
amirreza-sf80 wants to merge 1 commit into
Conversation
94e4598 to
931b88f
Compare
|
i'm unsure how i should write the release note |
931b88f to
c2c5e3a
Compare
📊 Coverage Report for Changed FilesNote: Missing lines are warnings only. Some lines may not be covered by SQLite tests as they are database-specific. For more information about code coverage on pull requests, see the contributing documentation. |
medmunds
left a comment
There was a problem hiding this comment.
@amirreza-sf80 thanks for this! I'm working on the new EMAIL_PROVIDERS feature that will parallel CACHES/DATABASES/STORAGES/TASKS (ticket-35514). We plan to make alias available on EmailBackend instances like you're doing here for cache backends, so I'm actively following this PR and ticket.
I added a handful of suggestions for backwards compatibility.
b89dbf7 to
f6295fa
Compare
f6295fa to
9ff8b5d
Compare
|
Thank you for your contribution to Django! This pull request has one or more items that need attention before it can be accepted for review.
|
|
I see this PR adds some deprecation, but I does the deprecation need to be documented anywhere else? |
I think the built-in cache backend implementations—at least the So yes, this would seem to need a release note explaining the changes needed in custom/third-party cache backends. (And an entry in docs/internals/deprecation.txt.) |
a28b448 to
18f52a2
Compare
|
i added a deprecation note in release notes |
18f52a2 to
cd7b2fc
Compare
c474e70 to
364dc22
Compare
medmunds
left a comment
There was a problem hiding this comment.
This is looking great @amirreza-sf80. I have a handful of suggestions and comments beyond @easherma's helpful review.
Also, we'll need tests for the deprecation warnings. There are some tips for that in Deprecating a feature. At least one of the tests should have a custom cache backend like might be in a third-party package.
For docs/internal/deprecation.txt, features being deprecated in 6.2 are removed in 7.1, so you'd add a note to the 7.1 section.
medmunds
left a comment
There was a problem hiding this comment.
[Sorry, forgot to hit "submit" on one comment in my earlier review.]
medmunds
left a comment
There was a problem hiding this comment.
@amirreza-sf80 this looks pretty much ready to me. I flagged a couple of typos, and left an (optional) suggestion for simplifying the legacy case in the management command.
Also, could you squash this to a single commit and rebase it to the main branch? Both are needed before it can be merged.
It looks like the DEP 20 release naming changes have been merged into main, so when rebasing you may find that RemovedInDjango71Warning will need to be replaced with RemovedInDjango2029Warning.
| cache_alias = next( | ||
| ( | ||
| alias | ||
| for alias, cache in settings.CACHES.items() | ||
| if cache.get("LOCATION") == tablename | ||
| ), | ||
| "<<unknown>>", | ||
| ) | ||
| self.create_table(db, tablename, dry_run, cache_alias) |
There was a problem hiding this comment.
Suggestion: used a fixed string that is unlikely to be mistaken for a real CACHES alias:
| cache_alias = next( | |
| ( | |
| alias | |
| for alias, cache in settings.CACHES.items() | |
| if cache.get("LOCATION") == tablename | |
| ), | |
| "<<unknown>>", | |
| ) | |
| self.create_table(db, tablename, dry_run, cache_alias) | |
| self.create_table(db, tablename, dry_run, "<<unknown>>") |
(I agree with you that this code I had suggested for searching CACHES is "strange"—and unnecessarily complicated for a legacy branch.)
There was a problem hiding this comment.
so this works, since when we call create_table from this branch it doesn't really care what the alias is
but it does mean that different cache backends would get the same alias
this is probably not important in any way, but i feel like we shouldn't do it.
don't know what's right here
There was a problem hiding this comment.
self.create_table() creates a temporary cache backend instance that isn't exposed anywhere. And in this undocumented legacy branch, create_table only gets called one table at a time. I understand your concern, but I don't think there could be multiple cache backend instances with this "<<unknown>>" alias alive in memory at the same time.
Another reasonable option would be None, but that would require some additional work to avoid the warning in BaseCache.__init__() (e.g., using a sentinel object rather than None to detect the missing alias param).
2f60b56 to
1f09aff
Compare
|
rebased and squashed up to this point |
medmunds
left a comment
There was a problem hiding this comment.
Thanks for rebasing and updating the deprecations. There's a minor merge glitch and one untested deprecation warning.
| cache_alias = next( | ||
| ( | ||
| alias | ||
| for alias, cache in settings.CACHES.items() | ||
| if cache.get("LOCATION") == tablename | ||
| ), | ||
| "<<unknown>>", | ||
| ) | ||
| self.create_table(db, tablename, dry_run, cache_alias) |
There was a problem hiding this comment.
self.create_table() creates a temporary cache backend instance that isn't exposed anywhere. And in this undocumented legacy branch, create_table only gets called one table at a time. I understand your concern, but I don't think there could be multiple cache backend instances with this "<<unknown>>" alias alive in memory at the same time.
Another reasonable option would be None, but that would require some additional work to avoid the warning in BaseCache.__init__() (e.g., using a sentinel object rather than None to detect the missing alias param).
|
(Also, Django is quite picky about commit messages: if you could capitalize the "S" in "Fixed #36830 -- stored the cache alias…" and change the message body to past-tense sentences, that will save the merger a step.) |
609165c to
97340c6
Compare
97340c6 to
86634b8
Compare
|
Hi @amirreza-sf80, thanks for working on this! Adding A few observations and suggestions:
|
medmunds
left a comment
There was a problem hiding this comment.
@amirreza-sf80 thanks for sticking with this.
In addition to @VimalN2005's comments, I spotted a few other minor corrections in the docs.
df17b46 to
a88dab2
Compare
|
thank you |
these changes passed the CACHES dictionary keys to the cache backend when instantiating and stored it on the instance as self.alias, this was discussed on the new-features repository and is mostly used by 3rd-pary projects that need to know which cache they are using. thanks to Tim Schilling for the report, thanks to Sergei Maertens, Eric Sherman, Vimal Sahani, Mike Edmunds and Jonathan Biemond for reviews. Co-authored-by: Mike Edmunds <[email protected]>
i think it should only be explicit in BaseCache |
Trac ticket number
ticket-36830
Branch description
this feature has been discussed in django/new-features#95
this pr will pass the cache backend alias name to the backend when instantiating them
this will make cache consistant with other parts of django such as the ORM and django.tasks
it also helps 3rd party packages with more complex logics, as mentioned in the feature request
Checklist
mainbranch.