Very strange issues with collections.Mapping

Dan Stromberg drsalists at gmail.com
Thu Jan 18 19:50:18 EST 2018


Probably not what you want to hear, but this might be a good place for an SSCCE.

On Thu, Jan 18, 2018 at 1:37 PM, Jason Swails <jason.swails at gmail.com> wrote:
> Hello!
>
> I am running into a very perplexing issue that is very rare, but creeps up
> and is crashing my app.
>
> The root cause of the issue comes down to the following check returning
> true:
>
> isinstance([], collections.Mapping)
>
> Obviously you can get this behavior if you register `list` as a subclass of
> the Mapping ABC, but I'm not doing that.  Because the issue is so rare (but
> still common enough that I need to address it), it's hard to reproduce in a
> bench test.
>
> What I am going to try is to essentially monkey-patch
> collections.Mapping.register with a method that dumps a stack trace
> whenever it's called at the time of initial import so I can get an idea of
> where this method could *possibly* be getting called with a list as its
> argument.
>
> The annoying thing here is that wherever the bug is happening, the crash
> happens *way* far away (in a third-party library).  I've also determined it
> as the root cause of two crashes that seem completely unrelated (except
> that the crash is caused by a list not behaving like a dict shortly after
> isinstance(obj, collections.Mapping) returns True).  These are the
> libraries I'm using:
>
> amqp
> billiard
> celery
> dj-database-url
> Django
> django-redis-cache
> enum34
> gunicorn
> kombu
> newrelic
> psycopg2
> pyasn1
> pytz
> redis
> requests
> rsa
> six
> vine
> voluptuous
>
> It's a web application, as you can probably tell.  The main reason I ask
> here is because I'm wondering if anybody has encountered this before and
> managed to hunt down which of these libraries is doing something naughty?
>
> Thanks!
> Jason
>
> --
> Jason M. Swails
> --
> https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list