@@ -326,12 +326,17 @@ def get_db_field_types(self) -> Optional[dict[str, str]]:
326
326
"""
327
327
if not self .has_db_field : # pragma: nocoverage
328
328
return None
329
+ default = getattr (self , "SQL_TYPE" )
329
330
return {
330
- "" : getattr ( self , "SQL_TYPE" ) ,
331
+ "" : default ,
331
332
** {
332
- dialect : _db ["SQL_TYPE" ]
333
- for dialect , _db in self ._get_dialects ().items ()
334
- if "SQL_TYPE" in _db
333
+ dialect : sql_type
334
+ for dialect , sql_type in (
335
+ (key [4 :], self .get_for_dialect (key [4 :], "SQL_TYPE" ))
336
+ for key in dir (self )
337
+ if key .startswith ("_db_" )
338
+ )
339
+ if sql_type != default
335
340
},
336
341
}
337
342
@@ -342,8 +347,18 @@ def get_for_dialect(self, dialect: str, key: str) -> Any:
342
347
:param dialect: The requested SQL Dialect.
343
348
:param key: The attribute/method name.
344
349
"""
345
- dialect_data = self ._get_dialects ().get (dialect , {})
346
- return dialect_data .get (key , getattr (self , key , None ))
350
+ try :
351
+ dialect_cls = getattr (self , f"_db_{ dialect } " ) # throws AttributeError if not present
352
+ dialect_value = getattr (dialect_cls , key ) # throws AttributeError if not present
353
+ except AttributeError :
354
+ pass
355
+ else : # we have dialect_cls and dialect_value, so lets use it
356
+ # it could be that dialect_value is a computed property, like in CharField._db_oracle.SQL_TYPE,
357
+ # and therefore one first needs to instantiate dialect_cls
358
+ if isinstance (dialect_value , property ):
359
+ return getattr (dialect_cls (self ), key )
360
+ return dialect_value
361
+ return getattr (self , key , None ) # there is nothing special defined, return the value of self
347
362
348
363
def describe (self , serializable : bool ) -> dict :
349
364
"""
0 commit comments