Skip to content

Lock.acquire() interface change with 4.3.2 #2218

Closed
@timhanus

Description

@timhanus

Version: 4.3.2 + 4.3.3

Platform: Python 3.7.15/Linux

Description:
I recently upgraded redis-py to the latest version(4.3.3) and began seeing TypeErrors during non-blocking acquisition of locks. It seems like this PR (#2137) introduced an interface change to the Lock.acquire() method.

Any version <= 4.3.1 allowed two ways to acquire a non-blocking lock.

  • lock.acquire(False)
  • lock.acquire(blocking=False)

In versions 4.3.2 and 4.3.3 the lock.acquire(False) gives TypeError: acquire() takes 1 positional argument but 2 were given and forces us to use the blocking= keyword arguments.

This library https://github.com/sqlalchemy/dogpile.cache/ (probably among others?) uses this redis Lock().acquire() and a threading.Lock().acquire() interchangeably.
https://docs.python.org/3/library/threading.html#threading.Lock.acquire
https://github.com/sqlalchemy/dogpile.cache/blob/main/dogpile/lock.py#L126

To maybe belabor the point. This script runs under 4.3.1 but not under 4.3.2

import redis
client = redis.Redis()
lock = client.lock('lockName')
if lock.acquire(False):
    print("lock acquired!")
    lock.release()

To me, this seems like introducing a breaking change in a patch release which caught me off guard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions