Repository navigation
chore(deps): update dependency pika to v1.5.0 - #21
Merged
Merged
Conversation
renovate
Bot
force-pushed
the
renovate/python-dependencies
branch
from
November 24, 2026 19:34
1dfb5af to
90bb945
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
==1.4.4→==1.5.0Release Notes
pika/pika (pika)
v1.5.0Compare Source
Twelve changes are worth reading before you upgrade. One adds
pika.Connection, three can turn a passing build red, two change what a working application observes when it cancels a consumer or closes a channel, one lets RabbitMQ close a channel sooner after a consumer timeout, one refuses messages larger than 64 MiB, one changes what the Twisted adapter reports when a connection closes, one closes the connection when a consumer or reply callback raisesBlockingIOError, one changes the Python types that field-table numbers decode to, and one makes URLssl_optionsverify the broker.pika.Connectionis new, and is the connection to use1.5.0 introduces
pika.Connectionand itsChannel, a connection that runs its own IOLoop on a background thread and offers a thread-safe blocking API that does not stall heartbeats while your code processes a message. There is nothing to migrate from: these classes are new in this release, andpika.Connectionis the documented import.from pika.adapters.thread_safe_connection import Connectionalso works, though the module moves in 2.0 (see #1681).Channelis not exported frompika, because channels come fromConnection.channel().If you are starting new code, use
pika.Connection. If you have existing code on one of the adapters below, it keeps working in 1.5.0 and the deprecation notice tells you where it is going.The other adapters now emit a
DeprecationWarning, which may fail your testsBlockingConnection,TornadoConnection,TwistedProtocolConnectionandGeventConnectioneach warn from their constructor that they will be removed in Pika 2.0. They all still work.The upgrade risk is that a
DeprecationWarningraised from a constructor is a hard error for anyone running with warnings-as-errors, which is a common test configuration. It fires at construction, before any I/O, so it does not depend on reaching a broker:The same happens under
python -W errorandwarnings.simplefilter('error').BlockingConnectionis pika's most widely used entry point, so this is both likely and likely to be misread as pika being broken rather than as an intentional notice. Outside a test runner it is usually invisible, because Python's default filters hideDeprecationWarningunless it is triggered from__main__; pytest is what turns it back on.Either filter it or migrate. The warning uses
stacklevel=2, so it is reported against the line that constructs the connection rather than against pika, and a filter scoped to the pika module does not match. Match on the message instead:python -W 'ignore:BlockingConnection is deprecated' your_app.pyThe two forms are not interchangeable. In
filterwarningsthe message is a regular expression, while-Won the command line, forpythonand forpytestalike, matches it as a literal prefix, so thepyproject.tomlpattern given as a-Wargument matches nothing and the warning still fails the run.Cancelling a consumer no longer rejects the messages still arriving for it
A
Basic.Canceldoes not stop the broker immediately: the specification allows it to keep dispatching until it sendsBasic.CancelOk, and pika used to reject every delivery that arrived in that window, or discard it outright for anauto_ackconsumer. Discarding loses the message, because anauto_ackdelivery has no copy left at the broker, and rejecting is a decision pika was making on your behalf that no other client makes. Measured on RabbitMQ 4.3.6, closing a channel with anauto_ackconsumer half a second after its first delivery, 400 messages,work_queue_maxsize=50and a 50 ms callback. At 8 KiB bodies withclose(timeout=10): 339 of 400 lost before this change, 179 to 189 across five runs after it.close(timeout=None)loses none after the change, at either body size, and lost the same 339 before it, because that loss was the cancel window rather than the budget. At 64 bytes the deliveries still queued when a bounded close returns fit in the work queue, so the worker finishes them and nothing is lost; at 8 KiB they do not fit and the excess is discarded when the pool shuts. Quote the whole configuration with any figure from this area, because the message count, body size, queue size, callback cost and timeout all move it.utils/measure_close_loss.pyin the repository reproduces each of them.Those deliveries are now passed to your callback instead, which is what the Java client does, as long as the channel is still open.
One thing follows for existing code: a consumer callback can now run for a message that arrives after you called
basic_cancel, so a callback that assumed cancellation was immediate may see further deliveries.BlockingChannel.basic_cancelstill rejects them for anauto_ack=Falseconsumer, so they return to the queue at once as before, and its return value is unchanged; the channel no longer does that rejecting, the wrapper does. The generator-styleBlockingChannel.canceldiscards them instead, which #1767 covers.channel.close()on an asynchronous adapter still discards those deliveriesA channel that is closing discards them, because a callback could not acknowledge one anyway and the attempt would abort the connection; the Java client discards them at the same point.
Channel.closecancels each consumer without waiting for the broker to confirm, so this is what a barechannel.close()does onSelectConnection,AsyncioConnection,TornadoConnectionandGeventConnection. A discarded delivery is redelivered to the next consumer withauto_ack=Falseand lost withauto_ack=True. Pika now logs a warning naming the count as the channel closes.pika.ConnectionandBlockingConnectionare unaffected and keep every delivery across a close, since both cancel their consumers and wait for the broker to confirm before closing anything. To get the same guarantee from an asynchronous adapter, cancel each consumer with a callback and close the channel from the lastBasic.CancelOk; the channel documentation has the pattern. Pika 2.0 removes these adapters, which leavesConnectionand itsChannelas the only close path and so retires the gap rather than fixing it.A consumer RabbitMQ cancels for a timeout is released at once, so its channel can close sooner
On RabbitMQ 4.3 and later, a consumer on a quorum queue whose delivery exceeds the consumer timeout is cancelled with
Basic.Cancelinstead of having its channel closed. pika now confirms that cancellation withBasic.CancelOk, as the Java, .NET and Go clients do, so the broker releases the consumer at once instead of after its own 10 second wait.If the consumer still holds another unacknowledged delivery, the broker closes the channel with 406
PRECONDITION_FAILEDwhen that delivery times out as well. With 1.4.x that happened only when the second delivery timed out more than 10 seconds after the first; it now happens whenever it times out after the cancellation. Code that handles the cancellation should also expect the channel to close, or acknowledge within the timeout, raiseconsumer-timeout, or lower the prefetch. The broker side is discussed in rabbitmq/rabbitmq-server#18207.Messages larger than 64 MiB now close the connection
pika now refuses an inbound message whose body is larger than
max_inbound_message_body_size, 64 MiB by default, and a frame larger than that limit or 128 KiB, whichever is greater. Either closes the connection withMessageBodyTooLargeErrororFrameTooLargeError, both subclasses ofAMQPConnectionError. The Java and .NET clients use the same 64 MiB default. RabbitMQ refuses messages above its ownmax_message_size, 16 MiB by default, so the limit is reached only when the broker is configured to allow larger messages.If you consume larger messages, raise the limit with
ConnectionParameters(max_inbound_message_body_size=...)or?max_inbound_message_body_size=in a URL, up to 512 MiB, RabbitMQ's own maximum. A refused message delivered withoutauto_ackis requeued, so a consumer that reconnects is closed again: raise the limit, or dead-letter or remove the message on the broker. Withauto_ackthe broker has already discarded it. Returned messages andbasic_getreplies are checked too, so a publisher can be closed by its own oversized mandatory message coming back.TwistedProtocolConnectionreports why it closed, notConnectionDoneWhen pika closes a Twisted connection, the reason now reaches the
closeddeferred, theon_close_callback, and pending channel and queue deferreds, as on the other adapters, instead oftwisted.internet.error.ConnectionDone:ConnectionClosedByClientafterclose(), which is also whatyield connection.close()returns;ConnectionClosedByBrokerwhen the broker closes it;AMQPHeartbeatTimeout;ConnectionBlockedTimeout; and the size errors above. Code that traps or tests forConnectionDonemust handle these instead. A peer that drops the connection without pika closing it still reportsConnectionDone.A
BlockingIOErrorfrom a consumer or reply callback now closes the connectionOn a connection without TLS,
SelectConnection,AsyncioConnection,TornadoConnectionandGeventConnectionused to treat aBlockingIOError, or anyOSErrorwith a would-block errno, raised by a callback pika runs for a received frame (a consumer, RPC-reply or close callback) as the socket having no more data: pika logged it at ERROR with a traceback, kept the connection open, and left the frames after it unprocessed until the next read. It now closes the connection withStreamLostError, as any other exception from those callbacks does. A callback that does its own non-blocking I/O should catch the error itself.pika.compatis goneThe module is removed. It held Python 2 compatibility shims and platform checks, was never documented as public API, and nothing in pika imports it any more. It had no leading underscore, though, so it has been importable for years and an upgrade turns
import pika.compatintoModuleNotFoundError.Twelve of its names moved to
pika._utils:ON_LINUX,ON_OSX,ON_WINDOWS,LINUX_VERSION,SOL_TCP,HAVE_SIGNAL,RE_NUM,time_now(),as_bytes(),to_digit(),get_linux_version()andnonblocking_socketpair(). That module is private, so it is not a migration target; copy what you need instead. Four that are gone were Python 2 artefacts, and the standard library covers each:byte()(bytes((n,))),SOCKET_ERROR(OSError),AbstractBase(abc.ABC),str_or_bytes((str, bytes)).pika.spec.str, which wasstr = bytes, goes with them.longis gone too; in a field table,pika.data.LongLongreplaces it, as the next section describes.64-bit field-table integers keep their type, and floats decode as
floatAn
lorLfield-table value now decodes aspika.data.LongLong, anintsubclass that is always sent asl, so a header passed on keeps its 64-bit type, as it did with 1.4.x'slong. Wrap anintinLongLongto send it asl, which is what a Java consumer reads asLong; a plainintis still sent asIwhen it fits a signed 32 bits. Anfordvalue now decodes as afloat, where 1.4.x truncated it to an integer.URL
ssl_optionsnow always verify the brokerA URL whose
ssl_optionssetprotocolto anything other thanPROTOCOL_TLS_CLIENTused to build a context that accepted any certificate for any host, becausessl.SSLContextstarts atCERT_NONEfor those protocols. Every URLssl_optionscontext now requires a certificate that chains to the named CA, or to the system CAs when none is named, and checks the host name, asssl.create_default_context()does. A connection that only worked because nothing was checked now fails at the TLS handshake. No URL key turns verification off; to connect without it, build anssl.SSLContextyourself and pass it inpika.SSLOptions.pika.specis now annotated, which may fail your type checkerPika ships a
py.typedmarker, so a type checker reads pika's own annotations.pika.specis generated code and was previously excluded from pika'smypyconfiguration, which left every field of a decoded frame typed asAny.Anysilences all checking, so a downstreammypyrun that was clean can go red on upgrade without any change on your end. The most common line in every pika tutorial is affected:Two properties of the generated code account for it. Every generated constructor defaults its arguments to
None, so fields are optional even though a frame off the wire always carries them. And AMQPshortstrhas no declared encoding, so pika falls back to rawbyteson invalid UTF-8, makingrouting_key,exchangeandconsumer_tagallstr | bytes | None.The errors are accurate and the annotations are an improvement, so nothing here should be reverted. The FAQ covers the narrowing idioms: https://pika.github.io/pika/latest/faq/
pyrightusers see little change, since it reported most of these already.Configuration
📅 Schedule: (UTC)
* * 1 * *)🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.