@@ -14,12 +14,12 @@ def _is_readonly():
1414
1515
1616def _get_readonly_dbs ():
17- read_on_db_names = []
17+ read_only_db_names = []
1818 for db_key in getattr (settings , "DB_READ_ONLY_DATABASES" , tuple ()):
1919 db = settings .DATABASES .get (db_key )
2020 if db :
21- read_on_db_names .append (db ["NAME" ])
22- return read_on_db_names
21+ read_only_db_names .append (db ["NAME" ])
22+ return read_only_db_names
2323
2424
2525class ReadOnlyCursorWrapper (object ):
@@ -54,16 +54,12 @@ class ReadOnlyCursorWrapper(object):
5454 )
5555
5656 def __init__ (self , cursor , db , read_only = None , readonly_dbs = None ):
57-
58- if read_only is None :
59- read_only = _is_readonly ()
60- if readonly_dbs is None :
61- readonly_dbs = _get_readonly_dbs ()
62-
6357 self .cursor = cursor
6458 self .db = db
65- self .readonly = read_only
66- self .readonly_dbs = readonly_dbs
59+ self .readonly = _is_readonly () if read_only is None else read_only
60+ self .readonly_dbs = (
61+ _get_readonly_dbs () if readonly_dbs is None else readonly_dbs
62+ )
6763
6864 def execute (self , sql , params = ()):
6965 # Check the SQL
@@ -93,9 +89,15 @@ def _write_sql(self, sql):
9389 )
9490
9591 def _write_to_readonly_db (self ):
96- return (
97- not self .readonly_dbs or self .db .settings_dict ["NAME" ] in self .readonly_dbs
98- )
92+ """"
93+ Is this an access to a readonly database?
94+ """ "
95+ if not self .readonly_dbs :
96+ # All dbs are readonly
97+ return True
98+
99+ # Is the db in this list of readonly dbs?
100+ return self .db .settings_dict ["NAME" ] in self .readonly_dbs
99101
100102 @property
101103 def _last_executed (self ):
0 commit comments