Code

#19340 closed Bug (invalid)

django.forms.Field is not thread-safe

Reported by: anonymous Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal Keywords: thread-safe
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.forms.Field has the 'creation_counter' attribute which is incremented when an instance of django.forms.Field (or one of its subclasses) is created. I DO understand that it's a bit unusual to create
forms in the runtime, so this must not be a big issue (or not a bug at all), but it should be documented somewhere.

In [231]: from django import forms

In [232]: forms.Field.creation_counter
Out[232]: 0

In [233]: from threading import Thread

In [234]: def f():
   .....:       for x in xrange(10000):
   .....:               forms.Field()
   .....:      

In [235]: ths = [Thread(target=f) for x in xrange(4)]

In [236]: for t in ths: t.start()

In [237]: for t in ths: t.join()

In [240]: forms.Field.creation_counter
Out[240]: 35409

Attachments (0)

Change History (1)

comment:1 Changed 20 months ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

I'm not convinced this is a problem in practice. The creation counter is only used to establish field order, so as long as it's monotonically increasing on each form instance, it shouldn't matter than the values aren't sequential.

If you can demonstrate that it's a problem in practice, feel free to reopen.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.