#29867: cache.get_or_set won't cache None results -----------------------------------------------+------------------------ Reporter: phill-tornroth | Owner: nobody Type: Bug | Status: new Component: Core (Cache system) | Version: 2.1 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -----------------------------------------------+------------------------ `get_or_set` docstring says "If the key does not exist, add the key and set it to the default value." -- but that's not quite what it does. It will perform a set if the key doesn't exist, ''or if the cached value is None''.
I think in order to be doing what it says on the tin it'd need to be: {{{ if self.has_key(key, version=version): return self.get(key, version=version) else: if callable(default): default = default() if default is not None: self.add(key, default, timeout=timeout, version=version) # Fetch the value again to avoid a race condition if another # caller added a value between the first get() and the add() # above. return self.get(key, default, version=version) }}} I'd find this useful in cases where None was an expensive result to arrive at. If there's spiritual alignment with the suggestion, I'm happy to prepare and submit a change with tests. -- Ticket URL: <https://code.djangoproject.com/ticket/29867> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/057.2c68274dde1c84af4836f591c112a85d%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.