@@ -326,12 +326,17 @@ def get_db_field_types(self) -> Optional[dict[str, str]]:
326326 """
327327 if not self .has_db_field : # pragma: nocoverage
328328 return None
329+ default = getattr (self , "SQL_TYPE" )
329330 return {
330- "" : getattr ( self , "SQL_TYPE" ) ,
331+ "" : default ,
331332 ** {
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
335340 },
336341 }
337342
@@ -342,8 +347,18 @@ def get_for_dialect(self, dialect: str, key: str) -> Any:
342347 :param dialect: The requested SQL Dialect.
343348 :param key: The attribute/method name.
344349 """
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
347362
348363 def describe (self , serializable : bool ) -> dict :
349364 """
0 commit comments