if features.needs_datetime_string_cast field of object under the db key of connections dictionary is true and current_expires is not an instance of datetime object.
if ( connections [ db ] . features . needs_datetime_string_cast and not isinstance ( current_expires , datetime ) ) :