Opened 8 years ago

Closed 8 years ago

#5367 closed defect (fixed)

python gotcha: mutable type in __init__()

Reported by: aagbsn Owned by: aagbsn
Priority: Medium Milestone:
Component: Circumvention/BridgeDB Version:
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:



init arguments are parsed only once, so the same list will be shared with _all_ instance objects.

Child Tickets

Change History (2)

comment:1 Changed 8 years ago by aagbsn

Status: newneeds_review

Simple fix:

diff --git a/lib/bridgedb/ b/lib/bridgedb/
index a1b837a..b67edf2 100644
--- a/lib/bridgedb/
+++ b/lib/bridgedb/
@@ -50,7 +50,7 @@ class WebResource(twisted.web.resource.Resource):
     def __init__(self, distributor, schedule, N=1, useForwardedHeader=False,
                  useRecaptcha=False,recaptchaPrivKey='', recaptchaPubKey='',
-                 domains=[]): 
+                 domains=None): 
         """Create a new WebResource.
              distributor -- an IPBasedDistributor object
              schedule -- an IntervalSchedule object
@@ -63,6 +63,9 @@ class WebResource(twisted.web.resource.Resource):
         self.nBridgesToGive = N
         self.useForwardedHeader = useForwardedHeader
         self.includeFingerprints = includeFingerprints
+        # do not use mutable types as __init__ defaults!
+        if not domains: domains = [] = domains
         # recaptcha options

comment:2 Changed 8 years ago by aagbsn

Resolution: fixed
Status: needs_reviewclosed
Note: See TracTickets for help on using tickets.