Skip to content

Conversation

jvanasco
Copy link
Member

@jvanasco jvanasco commented Aug 5, 2025

This is the idea for using typedicts

I also updated some typing and docstrings

Change-Id: I30619425e1e1e4ca43286be35a8c4a85658a8acb
include missing NO_VALUE on docstrings

Change-Id: I79c4657d5ea8778e2932bae3e81725af27bbef85
Change-Id: I8cd5d4fbf7eabf03e48f5434e6c50dacd07dfd3c
@jvanasco jvanasco marked this pull request as draft August 5, 2025 04:29
Change-Id: Ib1c0a38f072676f33254a91312e7237c129850f2
@jvanasco jvanasco marked this pull request as ready for review August 5, 2025 14:04
@zzzeek zzzeek requested review from CaselIT and sqla-tester August 6, 2025 16:43
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 1821cb9 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 1821cb9: https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6081

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, left just a suggestion to dry up a bit the definition

* applied typing to other backends
* standardized all backends to operate on a copy of the Dict passed in
  Some backends did this, others did not.

Change-Id: I90084c6d0ad23d7bb9988664c2cef1a739fa3ff1
@jvanasco jvanasco marked this pull request as draft August 11, 2025 15:19
Change-Id: I4b912cfdb7fdae970bd95d418e059bb9965b5832
@jvanasco jvanasco marked this pull request as ready for review August 11, 2025 16:21
@jvanasco
Copy link
Member Author

Ready for another review.

General Concerns:

Redis Backend:

test_decorator.py

  • test_sha1_key_mangler_bytes_py3k uses bytes
  • test_sha1_key_mangler_bytes_py2k should this exist anymore?

dogpile/cache/util.py

  • not really sure how to type the callable args and returns. i left them generic.

Backends
There was a lot of cruft from decades of dogpile and changing styles. i standardized everything to the following:

  • _arguments = arguments.copy() - some backends still .pop() a value off the arguments dict., others use .get(). iirc this was a legacy from operating on the dict then passing it on to a third party library constructor. i did not change pop vs get, but everything now operates on a copy. I also cast the copy to Dict, so items can be popped (that emits errors on typeddicts). I could easily do that.
  • to deal with superclasses and typing, I created another .copy() and changed type with cast. I'm not particularly happy with this, but it works.

I wasn't too happy with this approach, but I there is no real performance/memory hit (it happens on backend startup), and most new backends will copy/edit an existing backend - so I wanted to set a unified style to reinforce.

This definitely needs review and feedback, but IMHO these upgrades to typing are helping find issues.

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left a suggestion, looks great overall to me

regarding get vs pop, in my opinion we could replace all of the with gets, but let's wait for @zzzeek opinion


def __init__(self, arguments):
def __init__(self, arguments: DBMBackendArguments):
_arguments = cast(Dict, arguments.copy())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this backend doesn't modify the dicy, maybe we could avoid this?

I mean it may make sense for backends that use pop, but for the other maybe not? this applies also to the other cases

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to standardize how all the backends work, because people will use them as reference when implementing a new one.

self.username = _arguments.get("username", None)
self.password = _arguments.get("password", None)
self.tls_context = _arguments.get("tls_context", None)
_arguments_super = cast(GenericMemcachedBackendArguments, _arguments)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't great, also considering that this method doesn't modify the argument

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not thrilled with it either, this was purely to appease the mypy.

.. versionadded:: 1.1.5
:param dead_timeout: Time in seconds before attempting to add a node
:param hashclient_dead_timeout: Time in seconds before attempting to add a node
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this require a versionchanged note in the docstring and/or backward compat property what warns on access?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This is just correcting a docstring error. The docstring references dead_timeout, the code uses hashclient_dead_timeout see main:

https://github.com/sqlalchemy/dogpile.cache/blob/main/dogpile/cache/backends/memcached.py#L610

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh ok, the docs is of the dictionary not of the class attributes. got it.

@jvanasco
Copy link
Member Author

regarding get vs pop, in my opinion we could replace all of the with gets,

I'd prefer that. IIRC, the usage of pop is a legacy behavior. these constructors once popped off the vars they didn't need, then passed the mutated dicts onto other functions (such as the redis or memcached client contructors).

If that is not the case anymore, I'd love to standardize everything to whatever style you and mike prefer. that would drop the need for .copy() of args as well. i'd just like to see every backend implemented with the same coding conventions.

@CaselIT
Copy link
Member

CaselIT commented Aug 18, 2025

I would go for get, but let's wait for mike here

@zzzeek
Copy link
Member

zzzeek commented Aug 18, 2025

regarding get vs pop, in my opinion we could replace all of the with gets,

I'd prefer that. IIRC, the usage of pop is a legacy behavior. these constructors once popped off the vars they didn't need, then passed the mutated dicts onto other functions (such as the redis or memcached client contructors).

If that is not the case anymore, I'd love to standardize everything to whatever style you and mike prefer. that would drop the need for .copy() of args as well. i'd just like to see every backend implemented with the same coding conventions.

OK, yes we can use get, but we are in a collision here. Please take a look at github.com//pull/274 which is adding tests for this functionality and also fixing the memory backend. I've asked for some changes and I'm not sure the contributor understands what I'm asking for (I want a test in test_region for all backends illustrating that backends dont mutate the parameter dictionaries).

@jvanasco
Copy link
Member Author

Let me see what I can pull together in the next 30 minutes.

fixed valkey default for lock_sleep

Change-Id: I03c80c105be4ec3b280d57f340b050b16c4d937a
@jvanasco
Copy link
Member Author

I added some backend tests as BackendArgsAntiMutationTest. I'm hoping the redis/valkey clusters pass in the cloud; I can't run them locally due to an instant fail if they cluster servers are not available.

while doing this, I noticed there are no tests for the redis & valkey cluster backends.

I did something weird, as I wasn't sure how to pull off elegantly. when a backend is tested, I add it to BackendArgsAntiMutationTest.backends_tested. on the class teardown, I iterate over the plugin loader to ensure this test has run on every backend that is registered. This will cause a fatal Error on the final test if a new backend has been created, but is not added to this test class. You may think of a better way to implement this.

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work, just an additional suggestion, but it's fine as is too

Change-Id: Ib7bf3ebf825c0823e70b29b0ef5ee5f21010616a
@CaselIT CaselIT requested a review from sqla-tester August 19, 2025 17:45
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 0680d81 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Failed to create a gerrit review, git squash against branch 'main' failed

@CaselIT
Copy link
Member

CaselIT commented Aug 21, 2025

@jvanasco could you merge with the main branch?

Change-Id: I4b00ec1e4faa45b204bc214099d0180c46b08145
@jvanasco
Copy link
Member Author

@CaselIT Done, but there is a merge commit

@CaselIT
Copy link
Member

CaselIT commented Aug 22, 2025

it's not an issue since gerrit will squash everything

@CaselIT CaselIT requested a review from sqla-tester August 22, 2025 07:24
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 9eb6fc3 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 9eb6fc3 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6081

@zzzeek
Copy link
Member

zzzeek commented Aug 22, 2025

im dying for either of this #270 or #274 to please put a test that is across all backends (meaning, in dogpile/cache/testing/fixtures) to assert that:

  1. keys that are consumed by backends remain in the argument dictionary afterwards
  2. keys that are unknown to the backend don't cause probelms and also remain in the argument dictionary

@jvanasco
Copy link
Member Author

im dying for either of this #270 or #274 to please put a test that is across all backends (meaning, in dogpile/cache/testing/fixtures) to assert that:

  1. keys that are consumed by backends remain in the argument dictionary afterwards
  2. keys that are unknown to the backend don't cause probelms and also remain in the argument dictionary

I implemented #1 in test_region as class BackendArgsAntiMutationTest; #2 would just be tossing in some random values. I can certainly shift it to a class-based system that is available to third party plugins who use those fixtures.

@jvanasco jvanasco mentioned this pull request Aug 23, 2025
@jvanasco
Copy link
Member Author

I switched the backend test from test_region to GenericBackendFixture as requested, it's in #275 as separate PR for easier comparison.

I do want to note there is no exiting test coverage (in general) for redis & valkey cluster backends. that is outside the scope of this though, as it will likely require a CI setup.

Change-Id: I90beea7da33de522de95e3e901410a5966aea024
Change-Id: I6a9b9f45ecb9c8acf6e030aacfb4ec2f28b0b689
@jvanasco
Copy link
Member Author

This has been updated against main. The previously requested tests were removed as they are now unnecessary.

@CaselIT CaselIT requested a review from sqla-tester September 11, 2025 07:21
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 8711197 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

Patchset 8711197 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/dogpile.cache/+/6081

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

Successfully merging this pull request may close these issues.

4 participants