Commit Graph

267 Commits

Author SHA1 Message Date
flolas c18e9626e1 raise access denied error when ack 2023-09-04 02:16:00 +06:00
mbierma 492776eb7f
fix: Prevent redis task loss when closing connection while in poll (#1733)
* Catch brpop before closing connection

* Update unit test

---------

Co-authored-by: mbierma <3448579-mbierma@users.noreply.gitlab.com>
2023-08-15 10:16:49 +06:00
Rafid K 862d0bc728
[fix #1726] Use boto3 for SQS async requests (#1759)
* [fix #1726] Use boto3 for SQS async requests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-27 10:06:41 +06:00
Tomer Nosrati 18edd4c848 Reverted unwanted constraint introduced in #1629 with max_retries not being able to be None (when it should) 2023-06-19 09:54:28 +06:00
Sebastian Kreft dd341709bf fix: allow deserializing any version of UUID
In PR #1575 a new serializer for UUIDs was introduced, however it fails when deserializing UUIDs which version is not within 1 and 5. Given that there's a new standard (https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04) ganining traction that introduces UUIDs v6, v7 and v8, we change the code to allow such versions.

In the test, we generate one UUID for each version using the package `uuid6` (https://github.com/oittaa/uuid6-python)
2023-06-15 18:57:24 +06:00
Daniel Garcia Moreno cb54c33f19 Support redis >= 4.5.2
The redis-py 4.5.2 changes the UnixDomainSocketConnection class so now
it inherits from AbstractConnection:
https://github.com/redis/redis-py/releases/tag/v4.5.2

This patch makes sure that the health_check_interval parameter is
checked for the __init__ method of the main class and also the bases, so
it doesn't fail with the newer version of redis-py.
2023-05-29 19:56:28 +06:00
Tom Sparrow 5062d53f94
SQS: avoid excessive GetQueueURL calls by using cached queue url (#1621)
* Fix #1618: avoid re-fetching queue URL when we already have it

`_get_from_sqs` was unnecessarily calling `get_queue_url` every
time even though the only place which calls `_get_from_sqs`
(that is `_get_async`) actually already knows the queue URL.

This change avoids hundreds of `GetQueueUrl` AWS API calls per hour
when using this SQS backend with celery.

Also `connection` is set by the one-and-only caller (and `queue` is
actually the queue name string now anyway so couldn't ever have
`.connection`) so remove the None default and unused fallback code.

* Clarify that `_new_queue` returns the queue URL

It seems that prior to 129a9e4ed0 it returned a queue
object but this is no longer the case so update comments
variable names accordingly to make it clearer.

Also remove the incorrect fallback which cannot
be correct any more given the return value has to
be the queue URL which must be a string.

* Unit test coverage for SQS async codepath

This key code path (which as far as I can see is
the main route when using celery with SQS) was
missing test coverage.

This test adds coverage for:
`_get_bulk_async` -> `_get_async` -> `_get_from_sqs`
2023-04-19 10:01:07 +06:00
Francis Charette-Migneault f86f1fc6e1
fix mongodb transport obsolete calls (#1694)
* fix mongodb transport obsolete calls + add test mock specs to check valid methods

* fix linting
2023-04-18 10:54:17 +06:00
Ismael Jiménez Sánchez ff031f73f2
fix: handle keyerror in azureservicebus transport when message is not found in qos and perform basic_ack (#1691)
* fix: handle keyerror when message is not found in qos and perform basic_ack

* fix: added tests for basic_ack

* fix: limit line length
2023-04-11 22:33:26 +06:00
Maxwell Muoto 9659f11ae1
Deprecate pytz and use zoneinfo (#1680)
* Main

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* Trigger Build

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* Fix

* noqas

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unused noqa

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* re-add import

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* use pytest-freezer (#1683)

* Main

* Trigger Build

* Fixes

* remove

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

* Lint

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2023-04-09 14:08:23 +06:00
Jason R. Coombs c310364cc0 Adapt the mock to correctly mock the behaviors as implemented on Python 3.10. Ref #1663. 2023-03-12 22:33:37 +06:00
Serhii Tereshchenko 6fe50f5985
refactor: Refactor utils/json (#1659)
* refactor: Refactor utils/json

* Update kombu/utils/json.py

* Update kombu/utils/json.py

* chore: Use older syntax (no walrus)

* chore: Update doscstrings

* chore: Fix pydocstyle complaints

* chore: Restore previous docstring
2023-03-02 16:18:21 +06:00
Jason Barnett d3ca0d562e azure service bus: add type annotations and use cached property 2023-01-05 00:34:46 +06:00
Jason Barnett 4fac6bc84c
add managed identity support to azure storage queue (#1631)
* add managed identity support to azure storage queue

* flake8 fixes
2022-12-27 00:51:47 +06:00
Tomer Nosrati 44025bfa52
Allowing `Connection.ensure()` to retry on specific exceptions given by policy (#1629)
* Added unit test: test_ensure_retry_errors_is_not_looping_infinitely()

* Added unit test: test_ensure_retry_errors_is_limited_by_max_retries()

* Added retry_errors arg to Connection.ensure() to allow applying retry policy for specific errors additionally
2022-12-18 12:34:57 +02:00
David Bossanyi 22b559684f
Allow azurestoragequeues transport to be used with Azurite emulator in docker-compose (#1611)
* Parse credential as a dict when using Azurite emulator

This more flexible credential allows the use of Azurite for integration testing in local docker-compose configurations.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix some lint errors

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-16 20:43:15 +06:00
Marti Raudsepp bfec7faf8d Fix errors from flake8 lint
Python's `del` is a statement, not a function, and doesn't need
parenthesis.
2022-10-12 20:47:19 +06:00
Marti Raudsepp 3a49533bc2
Add separate transport option for retry loop timeout (#1599)
* Add separate transport option for retry loop timeout

This only applies when using `Connect.default_channel`.

Before this change, the retry loop timeout was set equal to TCP connect timeout (`connect_timeout`), meaning when first connection attempt timeouted, no retry would be attempted.

Now if a new transport option `connect_total_timeout` is provided, this overrides `connect_timeout` for the retry loop (but not for TCP connect).

* Add tests

* Fix isort

* Rename to connect_retry_timeout

* Reformat

* connect_retry_timeout -> connect_retries_timeout

* Fix flake8
2022-10-12 19:41:04 +06:00
karajan1001 6ae9fac150 Solve Kombu filesystem transport not thread safe
partly fix: #398
1. add exclusive lock during the whole exchange file update.
2. add some unit test for file lock
2022-09-23 17:29:34 +06:00
Manuel Vázquez Acosta 2d88c43fef Make JSONEncoder keep the same type for date/datetime.
Otherwise Celery jobs start to get `datetime` in place of `date` and that
could lead to errors.

See https://github.com/celery/celery/issues/7754, related PR #1515.
2022-09-21 12:24:08 +06:00
Gao afcde0a0bd
Revert "Solve Kombu filesystem transport not thread safe (#1593)" (#1595)
This reverts commit 8699920e05.
2022-09-09 22:52:53 +06:00
Gao 8699920e05
Solve Kombu filesystem transport not thread safe (#1593)
* Solve Kombu filesystem transport not thread safe

fix: #398
Currently only write lock used in msg/exchange file written. Cause
reading in other thread got some incomplete result.

1. Add timeout for the lock acquire.
2. Add Share locks when reading message from filesystem.
3. Add a unit test for the `lock` and `unlock`
4. Add a unit test to test the lock during message processing.

* Replace deprecated function.
2022-09-07 21:54:28 +06:00
Shalabh Chaturvedi ec533af9c1
Fix incompatibility with redis in disconnect() (#1589)
* Accept *args in disconnect()

* Add test for redis connection timeout error
2022-08-25 23:47:52 +06:00
Shahar Lev 717ad3ddc9
hub: tick delay fix (#1587)
* hub: tick delay fix

todo and timer callbacks can perform actions that
require a tick callback to be executed right away
without polling.

the current order can cause issues
when using single worker with no prefetch (acks late).

related issue in celery:
https://github.com/celery/celery/issues/7718

* add unit test for hub delay fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-08-24 14:32:35 +06:00
Carlos Gottberg 10a673b17c
Avoid losing type of UUID when serializing/deserializing (#1575)
* Avoid losing type of UUID when serializing/deserializing

Serializing UUIDs as strs and deserializing them as strs can lead to
somewhat obscure bugs such as the one that led to the creation of this
PR in django-cacheback
https://github.com/codeinthehole/django-cacheback/pull/100 which some
would call unexpected behaviour.

After all, an UUID is altogether a different type from strs and if
bytes got their own serializer/deserializer for UUID the same logic
should apply.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update documentation for JSON serialization

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-07-17 23:09:40 +06:00
Dan Cecile 4440c649e0 Add WATCH to prefixed complex commands 2022-07-14 22:56:41 +06:00
eloranger 674a645356
Add support to SQS DelaySeconds (#1567)
* Add DelaySeconds to kwargs

* Add test

* add default value for DelaySeconds

* Fix tests and add check for properties

* Fix flake8 style issue

Co-authored-by: Edmund Lam <2623895+edmundlam@users.noreply.github.com>
2022-07-12 22:31:21 +06:00
dobosevych c4829754db
Datetime serialization and deserialization fixed (#1515)
* Datetime serialization and deserialization fixed

* Unit test fixed

* Unit test fixed

* Fixed pylint

* Added Undocumented Autodoc Modules

* Update kombu/utils/json.py

Co-authored-by: Omer Katz <omer.katz@omerkatz.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Clean and freeze now

* Clean and freeze now

* Clean and freeze now

* Clean and freeze now

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Omer Katz <omer.katz@omerkatz.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-05-31 11:21:04 +06:00
Marcelo Trylesinski 0a2f54eac2
Annotate `abstract.py` (#1522)
* Annotate `abstract.py`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* apply pre-commit

* Use quotes

* Add typing_extensions as requirement

* Add quotes

* Add quotes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-05-15 13:17:49 +06:00
Jonas Miederer b3e89101dc
Upgrade Azure Storage Queues transport to version 12 (#1539)
* updated azurestoragequeues transport for azure-storage-queues v12 + added basic tests

* fixed flake8 issues

* pinned azure-storage-queue lib to >= v12.0.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* azure-storage-queue>=12.2.0

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2022-04-23 14:15:49 +06:00
CountRedClaw 33e8e5a781
Kafka support (#1506)
* Add kafka support

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix checks

* Fix checks

* Update kombu/transport/confluentkafka.py

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>

* Add customization ability

* Add docs

* Fix pypi integration tests

* Fix pydocstyle

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Cleanup

* Disable PyPy tests

* Fix tests

* Add docs

Co-authored-by: ilbo0518 <ilia.borsuk@netcracker.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2022-04-21 23:40:41 +06:00
Marcelo Trylesinski 14d395aa85
Annotate `exceptions.py` and `clocks.py` (#1526)
* Annotate `exceptions.py`

* Annotate `clocks.py`
2022-04-18 18:52:26 +06:00
Jakub Pieńkowski 661d92222e
Support pymongo 4.x (#1536)
* Support pymongo 4.x

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix problems detected by CI

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-18 18:10:38 +06:00
Marcelo Trylesinski 7516daf7a7 Bump pyupgrade version and add __future__.annotations import 2022-04-15 14:16:57 +06:00
Sondre Lillebø Gundersen 87384a91c6 chore: Update `__exit__` signatures
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-04-12 20:41:29 +06:00
Marcelo Trylesinski 7d99b6f79f
Annotate `utils/uuid.py` and `utils/text.py` (#1514)
* Annotate `utils/uuid.py` and `utils/text.py`

* Use callable without any parameter

* Update kombu/utils/text.py
2022-04-12 20:39:42 +06:00
dobosevych 894ddfc8b6
Added possibility to serialize and deserialize binary messages in json (#1516)
* Added possibility to serialize and deserialize binary messages in json

* Flake8 fixed

* Hypothesis added to improve test range. Fixed issue b'\x80' serialization.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added docstring

* Fixed pylint

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-12 18:52:41 +06:00
Oliver Nemček aab2588c4a
Protect set of ready tasks by lock to avoid concurrent updates. (#1489)
When there is no locking then there is a possibility that multiple threads
manipulate with the same object at the same time.
The issue is manifested as:
```
RuntimeError: Set changed size during iteration
```

See: https://github.com/celery/celery/issues/7162
2022-03-24 16:49:17 +02:00
Gao 0282e1419f
Add fanout to filesystem (#1499)
* Create a folder for each queue when using filesystem transport and add fanout support

* clean up unused variables

* Add fanout support to filesystem transport

filesystem transport lacks of fanout support.

1. Add fanout support to filesystem transport.
2. Add a unit test for it.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove the refactoring work and make the test passed

1. Remove all of refactoring work
2. make the test pass

* Use pathlib for some Path operation

* Some reviewed changes

Co-authored-by: Yuriy Halytskyy <y.halytskyy@auckland.ac.nz>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-15 20:21:07 +06:00
Shane Hathaway 9b505f4297 Add an option to not base64-encode SQS messages.
Also simplify the base64 decoding logic so that we don't have to
run base64 decoding twice for every message.
2022-03-04 11:47:01 +06:00
vinay karanam 3475986ee0
Added global_keyprefix support for pubsub clients (#1495)
* Added global_keyprefix support for pubsub clients

* Added test cases
2022-02-28 16:48:09 +06:00
Michael Manganiello 2f3b153acc
Warn about missing hostname only when default one is available (#1488)
* Warn about missing hostname only when default one is available

The `No hostname was supplied` warning is affecting projects that use
AWS SQS (as detailed in #1357), as a hostname is not required when
setting up the broker URL. Instead, the official documentation [0] specifies
that the valid broker URL formats are:

* `sqs://`
* `sqs://aws_access_key_id:aws_secret_access_key@`

With these formats, the `kombu.utils.url.parse_url` util doesn't return
a hostname, and workers end up triggering the following warning:

> No hostname was supplied. Reverting to default 'None'

As the SQS transport doesn't provide a default value for hostname, this
diff changes the behavior to only warn the user when the hostname hasn't
been supplied but a default one is being set by the default connection
parameters for the defined transport.

Fixes #1357.

[0] https://docs.celeryproject.org/en/stable/getting-started/backends-and-brokers/sqs.html#configuration

* Use caplog default logging level of WARNING
2022-02-02 19:23:14 +06:00
Mads Jensen ac92e047c1
Remove use of OrderedDict in various places (#1483)
* Remove use of OrderedDict in Connection.info.

* Remove remnant use of collections.OrderedDict

* Undo QoS._delivered move to Python standard dictionary.

This requires more work to convert, due to a hack in how the dictionary
is used.

* Undo LRUCache.data to dict conversion.

It's also problematic, and caused tests to fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert QoS._delivered comment chagne.

* Update comment

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-30 19:46:45 +06:00
Mads Jensen 31a84d5b3d
Some small updates (#1486)
* Some small updates

* Update QpidException super-call to Python 3 syntax.
2022-01-30 18:34:54 +06:00
Denis Kubashevskiy 3ec6dc0fd1
Set redelivered property for Celery with Redis (#1484)
* Set redelivered property for Celery with Redis

Fixed setting `redelivered` value for Celery when Redis broker is used.

* Add `test_do_restore_message_celery` test

* Fix long line
2022-01-28 20:16:22 +06:00
John Koehl a7355ac442
Fix issue #789: Async http code not allowing for proxy config (#790)
* (Issue #789) Don't reset the proxy config in the async curl based http request building unless that is specified by the caller

* Test curl proxy only set when explicitly specified by caller

Co-authored-by: Adam Aljets <aljets@users.noreply.github.com>
2022-01-14 09:37:46 +06:00
Paul Brown 9c062bdca5
allow getting recoverable_connection_errors without an active transport (#1471)
* allow getting recoverable_connection_errors without an active transport

* move redis transport errors to class

* move consul transport errors to class

* move etcd transport errors to class

* remove redis.Transport._get_errors and references in tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix flake8 errors

* add integration test for redis ConnectionError

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-30 12:28:11 +06:00
Paul Brown 81ec90fbce
prevent redis event loop stopping on 'consumer: Cannot connect' (#1477)
* prevent redis event loop stopping on 'consumer: Cannot connect'

* fix flake8 errors

* simplify event pool polling started check
2021-12-25 10:24:08 +06:00
Mehdi Pourfar a9c4f9837c
respect connection timeout (#1458)
* pass timeout to ensure connection function

* test connection respect its timeout
2021-12-24 15:21:44 +06:00
Paul Brown 47781af050 prevent event loop polling on closed redis transports (and causing leak) 2021-12-24 09:25:47 +06:00