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(python): Handle DB cursor descriptions that contain more fields than the DBAPI2 standard #17468

Merged
merged 1 commit into from
Jul 7, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jul 7, 2024

Closes #17466.

Not all drivers adhere to the DBAPI2 standard1 for the cursor description; the standard specifies exactly 7 attributes, but MariaDB's native driver (and possibly others, though no reports of such yet) returns more.

Trivial fix to handle the additional params.

Footnotes

  1. https://peps.python.org/pep-0249/#cursor-attributes

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Jul 7, 2024
@alexander-beedie alexander-beedie added the A-io-database Area: reading/writing to databases label Jul 7, 2024
Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.47%. Comparing base (a9fb237) to head (705a411).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17468   +/-   ##
=======================================
  Coverage   80.46%   80.47%           
=======================================
  Files        1483     1483           
  Lines      194856   194856           
  Branches     2771     2771           
=======================================
+ Hits       156796   156812   +16     
+ Misses      37550    37534   -16     
  Partials      510      510           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -203,7 +203,7 @@ def _infer_dtype_from_cursor_description(
description: tuple[Any, ...],
) -> PolarsDataType | None:
"""Attempt to infer Polars dtype from database cursor description `type_code`."""
type_code, _disp_size, internal_size, precision, scale, _null_ok = description
type_code, _disp_size, internal_size, precision, scale, *_ = description
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL. Does that unpack the remainder?

Copy link
Collaborator Author

@alexander-beedie alexander-beedie Jul 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup; the _ will subsequently contain a sequence of "everything else" ;)

a, b, *c = [1,2,3,4,5,6,7,8,9]
a
# 1
b
# 2
c
# [3, 4, 5, 6, 7, 8, 9]

@ritchie46 ritchie46 merged commit e7915d8 into pola-rs:main Jul 7, 2024
18 checks passed
@ksr-sundar-0723
Copy link

Thank you folks, great work! Proud to be a polars user!!!

@alexander-beedie alexander-beedie deleted the db-cursor-desc branch July 7, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io-database Area: reading/writing to databases fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

read_database method cannot fetch data from mariadb database
3 participants