Repository: django/django
File: django/db/backends/base/features.py (Python)

Code before:
    # that should be skipped for this database.
    django_test_skips = {}

    supports_uuid4_function = False
    supports_uuid7_function = False
    supports_uuid7_function_shift = False

    def __init__(self, connection):
        self.connection = connection

    def __del__(self):
        del self.connection

    @cached_property
    def supports_explaining_query_execution(self):
        """Does this backend support explaining query execution?"""
        return self.connection.ops.explain_prefix is not None

    @cached_property
    def supports_inspectdb(self):
        with self.connection.cursor() as cursor:
            try:
                self.connection.introspection.get_table_list(cursor)
            except NotImplementedError:
                return False
            return True

    @cached_property
    def supports_transactions(self):
        """Confirm support for transactions."""
        with self.connection.cursor() as cursor:
            cursor.execute("CREATE TABLE ROLLBACK_TEST (X INT)")
            self.connection.set_autocommit(False)
            cursor.execute("INSERT INTO ROLLBACK_TEST (X) VALUES (8)")
            self.connection.rollback()
            self.connection.set_autocommit(True)
            cursor.execute("SELECT COUNT(X) FROM ROLLBACK_TEST")
            (count,) = cursor.fetchone()
            cursor.execute("DROP TABLE ROLLBACK_TEST")
        return count == 0

    def allows_group_by_selected_pks_on_model(self, model):
        if not self.allows_group_by_selected_pks:
            return False
        return model._meta.managed


Review comment (suggestion):
This matches what `inspectdb` does:
https://github.com/django/django/blob/68859a9b45f0b9d472c9277dc61e54afacc0da38/django/core/management/commands/inspectdb.py#L47-L54
I debated whether to use this implementation or to make it a boolean that the developer has to set to opt out. I could be convinced either way.

Code after:
    # to fail on this database.
    django_test_expected_failures = set()
    # A map of reasons to sets of dotted paths to tests in Django's test suite
    # that should be skipped for this database.
    django_test_skips = {}

    supports_uuid4_function = False
    supports_uuid7_function = False
    supports_uuid7_function_shift = False

    def __init__(self, connection):
        self.connection = connection

    def __del__(self):
        del self.connection

    @cached_property
    def supports_explaining_query_execution(self):
        """Does this backend support explaining query execution?"""
        return self.connection.ops.explain_prefix is not None

    @cached_property
    def supports_transactions(self):
        """Confirm support for transactions."""
        with self.connection.cursor() as cursor:
            cursor.execute("CREATE TABLE ROLLBACK_TEST (X INT)")
            self.connection.set_autocommit(False)
            cursor.execute("INSERT INTO ROLLBACK_TEST (X) VALUES (8)")
            self.connection.rollback()
            self.connection.set_autocommit(True)
            cursor.execute("SELECT COUNT(X) FROM ROLLBACK_TEST")
            (count,) = cursor.fetchone()
            cursor.execute("DROP TABLE ROLLBACK_TEST")
        return count == 0

    def allows_group_by_selected_pks_on_model(self, model):
        if not self.allows_group_by_selected_pks:
            return False
        return model._meta.managed