GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Percents de-escaping isn't handled when no parameters are used in the dbapi. · Issue #608 · googleapis/python-bigquery

This repository was archived by the owner on Mar 6, 2026. It is now read-only.
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Percents de-escaping isn't handled when no parameters are used in the dbapi. #608

Copy link
Copy link
Closed
#619
Closed
Percents de-escaping isn't handled when no parameters are used in the dbapi.#608
#619
Copy link
Assignees
plamut
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.dbapipriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@jimfulton
jimfulton
opened on Apr 14, 2021
Issue body actions
>>> import google.cloud.bigquery.dbapi
>>> conn = google.cloud.bigquery.dbapi.connect()
/home/jim/p/g/python-bigquery/google/cloud/bigquery/client.py:444: UserWarning: Cannot create BigQuery Storage client, the dependency google-cloud-bigquery-storage is not installed.
  warnings.warn(
>>> cursor = conn.cursor()
>>> cursor.execute("select 'foo %%', %(x)s", dict(x=1))
>>> cursor.fetchall()
[Row(('foo %', 1), {'f0_': 0, 'f1_': 1})]
>>> cursor.execute("select 'foo %%'", dict(x=1))
>>> cursor.fetchall()
[Row(('foo %',), {'f0_': 0})]
>>> cursor.execute("select 'foo %%'")
>>> cursor.fetchall()
[Row(('foo %%',), {'f0_': 0})]

Bonus:

if people don't escape:

>>> cursor.execute("select 'foo %'")
>>> cursor.fetchall()
[Row(('foo %',), {'f0_': 0})]
>>> cursor.execute("select 'foo %'", dict(x=1))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jim/p/g/python-bigquery/google/cloud/bigquery/dbapi/_helpers.py", line 273, in with_closed_check
    return method(self, *args, **kwargs)
  File "/home/jim/p/g/python-bigquery/google/cloud/bigquery/dbapi/cursor.py", line 172, in execute
    formatted_operation = _format_operation(operation, parameters=parameters)
  File "/home/jim/p/g/python-bigquery/google/cloud/bigquery/dbapi/cursor.py", line 460, in _format_operation
    return _format_operation_dict(operation, parameters)
  File "/home/jim/p/g/python-bigquery/google/cloud/bigquery/dbapi/cursor.py", line 434, in _format_operation_dict
    return operation % formatted_params
ValueError: unsupported format character ''' (0x27) at index 13

Activity

  1. product-auto-label
    added
    api: bigqueryIssues related to the googleapis/python-bigquery API.
    on Apr 14, 2021
  2. jimfulton
    added
    dbapi
    on Apr 14, 2021
  3. yoshi-automation
    added
    triage meI really want to be triaged.
    on Apr 15, 2021
  4. plamut
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    triage meI really want to be triaged.
    on Apr 16, 2021
  5. plamut
    self-assigned this
    on Apr 16, 2021
  6. jimfulton commented on Apr 16, 2021

    @jimfulton
    jimfulton
    on Apr 16, 2021
    ContributorAuthor
    More actions

    FTR, I have a local fix. It's pretty simple. In cursor.py:

    @@ -441,7 +461,7 @@ def _format_operation(operation, parameters=None):
                 ``parameters`` argument.
         """
         if parameters is None or len(parameters) == 0:
    -        return operation
    +        return operation.replace("%%", "%")
     
         if isinstance(parameters, collections_abc.Mapping):
    
  7. plamut commented on Apr 16, 2021

    @plamut
    plamut
    on Apr 16, 2021
    Contributor
    More actions

    @jimfulton So the expected behavior is to always de-escape in absence of parameters, no matter what?

    It might be breaking for some of the existing parameter-less queries that happen to contain %%, but it will at least be clear that de-escaping is consistently always applied.

  8. jimfulton commented on Apr 16, 2021

    @jimfulton
    jimfulton
    on Apr 16, 2021
    ContributorAuthor
    More actions

    I think de-escaping has to be done consistently.

    I tripped over this while testing the SQLAlchemy integration, which assumes consistent de-escaping.

  9. plamut commented on Apr 16, 2021

    @plamut
    plamut
    on Apr 16, 2021
    Contributor
    More actions

    Fair enough. We do need to assure a good changelog message, though (note to self when merging the PR).

  10. gcf-merge-on-green
    closed this as completedin #619on Apr 16, 2021
  11. gcf-merge-on-green
    added a commit that references this issue on Apr 16, 2021

    fix: consistent percents handling in DB API query (#619)

    This issue will close once commit 6502a60 is merged into the 'main' branch.
    6502a60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @plamut
    plamut

Labels

api: bigqueryIssues related to the googleapis/python-bigquery API.dbapipriority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.