googleapis / python-bigquery-sqlalchemy

SQLAlchemy dialect for BigQuery
MIT License
436 stars 130 forks source link

Feat: Updates colspec to account for sqlalchemy Enum #1111

Closed chalmerlowe closed 3 months ago

chalmerlowe commented 3 months ago

Flakybot was flagging a number of tests that failed when handling sqlalchemy Enums. In consultation with members of the sqlalchemy team, it was suggested to follow an approach similar to the one used by sqlite: To modify the colspec.

The backstory is this: We made a class (BQString) that inherits from sqlalchemy's String. BQString has one function (and only one). It will process string literals to replace single percents with double percents.

def process_string_literal(value):
    return repr(value.replace("%", "%%"))

class BQString(String):
    def literal_processor(self, dialect):
        return process_string_literal

Where the issue comes into play is this:

The problem is that Enum is a subclass of String, so if you are defining a new dialect specific class of String, you would need to accommodate for Enum as well. The simplest way assuming you don't need BQString's logic for Enum is to map Enum to itself, which would bypass the BQString type for Enum.

Fixes #1102 🦕 Fixes #1103 🦕 Fixes #1104 🦕 Fixes #1105 🦕 Fixes #1106 🦕 Fixes #1107 🦕 Fixes #1108 🦕

conventional-commit-lint-gcf[bot] commented 3 months ago

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot https://conventionalcommits.org/