File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ def override_current_site_id(site_id):
7272 Context manager that overrides the current site id for code executed
7373 within it. Used to access SiteRelated objects outside the current site.
7474 """
75+ if hasattr (override_current_site_id .thread_local ,'site_id' ):
76+ raise RecursionError (f'''override_current_site_id can't be nested''' )
7577 override_current_site_id .thread_local .site_id = site_id
7678 try :
7779 yield
Original file line number Diff line number Diff line change @@ -601,6 +601,16 @@ def test_override_site_id(self):
601601 self .assertEqual (current_site_id (), 2 )
602602 self .assertEqual (current_site_id (), 1 )
603603
604+ def test_nested_override_site_id (self ):
605+ self .assertEqual (current_site_id (), 1 )
606+ with override_current_site_id (2 ):
607+ self .assertEqual (current_site_id (), 2 )
608+ with self .assertRaises (RecursionError ):
609+ with override_current_site_id (3 ):
610+ self .assertEqual (current_site_id (), 3 )
611+ self .assertEqual (current_site_id (), 2 )
612+ self .assertEqual (current_site_id (), 1 )
613+
604614
605615class CSRFTestViews :
606616 def nevercache_view (request ):
You can’t perform that action at this time.
0 commit comments