Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Oauth2 in GSheets #438

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ repos:
# additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.910' # Use the sha / tag you want to point at
rev: 'v1.9.0' # Use the sha / tag you want to point at
hooks:
- id: mypy
exclude: ^templates/
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
Next
====

- Fix OAuth2 flow in GSheets (#438)

Version 1.2.17 - 2024-02-23
===========================

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ githubapi =
python-jsonpath>=0.10.3
gsheetsapi =
google-auth>=1.23.0
pyopenssl>=24.0.0
holidaysmemory =
holidays>=0.23
htmltableapi =
Expand Down
7 changes: 5 additions & 2 deletions src/shillelagh/adapters/api/gsheets/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ def _run_query(self, sql: str) -> QueryResults:
if response.encoding is None:
response.encoding = "utf-8"

if response.status_code != 200:
raise ProgrammingError(response.text)
try:
response.raise_for_status()
except Exception as ex:
self._check_permissions(ex)
raise ProgrammingError(response.text) from ex

if response.text.startswith(JSON_PAYLOAD_PREFIX):
result = json.loads(response.text[len(JSON_PAYLOAD_PREFIX) :])
Expand Down
4 changes: 2 additions & 2 deletions src/shillelagh/adapters/api/gsheets/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ def get_index_from_letters(letters: str) -> int:

"""
base26 = reversed([string.ascii_uppercase.index(letter) + 1 for letter in letters])
return (
return int(
sum(
value * (len(string.ascii_uppercase) ** i) for i, value in enumerate(base26)
)
- 1
- 1,
)


Expand Down
2 changes: 1 addition & 1 deletion src/shillelagh/backends/apsw/dialects/gsheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def do_ping(self, dbapi_connection: _ConnectionFairy) -> bool:
def get_table_names( # pylint: disable=unused-argument
self,
connection: _ConnectionFairy,
schema: str = None,
schema: Optional[str] = None,
sqlite_include_internal: bool = False,
**kwargs: Any,
) -> List[str]:
Expand Down
5 changes: 5 additions & 0 deletions tests/adapters/api/gsheets/adapter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,11 @@ def test_api_bugs(mocker: MockerFixture) -> None:
status_code=400,
headers={},
)
adapter.register_uri(
"GET",
"https://sheets.googleapis.com/v4/spreadsheets/3/developerMetadata/0",
status_code=200,
)

connection = connect(":memory:", ["gsheetsapi"])
cursor = connection.cursor()
Expand Down
Loading