Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#7676 closed (fixed)

django serializers are not thread safe!

Reported by: sector119 Owned by: nobody
Component: Core (Serialization) Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

HI All!

I have to deserialize, serialize objects in multiple threads with django serializers.

But when I run Deserializer = serializers.get_deserializer(SERIALIZATION_FORMAT) in my threads (more then one, with _one_ thread all works great) I get KeyError? in get_serializer function at return _serializers[format].Deserializer line because _load_serializers does not load all data at _serializers dict before another tread run get_deserializer at this another thread and completely populate serializers dictionary with all, builtin and user-defined serializers! That is why I think that get_(de)?serializers and/or _load_serializers must be thread safe like _populate function at AppCache?!

Attachments (2)

threadsafe_serializers.diff (1.3 KB ) - added by mrts 16 years ago.
Threadsafe initialization of the _serializers dict
threadsafe_serializers-same_public_api.diff (3.0 KB ) - added by mrts 16 years ago.
Don't break the public API and be explicit about what is and is not thread-safe.

Download all attachments as: .zip

Change History (10)

by mrts, 16 years ago

Attachment: threadsafe_serializers.diff added

Threadsafe initialization of the _serializers dict

comment:1 by mrts, 16 years ago

Has patch: set

sector119, please test if this fixes the problem.

comment:2 by sector119, 16 years ago

Thanks! It works fine for me!

comment:3 by sector119, 16 years ago

but why not use threading's RLock, acquire, release ?

comment:4 by mrts, 16 years ago

Locking is expensive and should be avoided if possible.

comment:5 by mrts, 16 years ago

Component: UncategorizedSerialization
milestone: 1.0

As this is a bug, I'd assume it's in scope for 1.0.

by mrts, 16 years ago

Don't break the public API and be explicit about what is and is not thread-safe.

comment:6 by Sung-jin Hong, 16 years ago

Triage Stage: UnreviewedAccepted

Looks Good To Me.

comment:7 by Russell Keith-Magee, 16 years ago

Resolution: fixed
Status: newclosed

(In [8370]) Fixed #7676 -- Modified serializer registration to be thread safe. Thanks to mrts for the patch.

comment:8 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top