cursor.description's type_code is always None, even though col_types is already available internally
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
Read src/crate/client/cursor.py's Cursor.description property and the type definitions and _resolve() helper in src/crate/client/converter.py. Check how col_types is populated and how existing cursor tests cover description; add coverage for the type_code value when column types are available. Done means the public description exposes each column's type code without requiring a configured Converter.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
`Cursor.description` (PEP 249) always returns `None` for every field after the column name, including `type_code`:
https://github.com/crate/crate-python/blob/main/src/crate/client/cursor.py
```python
@property
def description(self):
if self._closed:
return None
description = []
for col in self._result["cols"]:
description.append((col, None, None, None, None, None, None))
return tuple(description)
```
This isn't because the driver doesn't have the type information. `self._result["col_types"]` is already populated from the same HTTP response (CrateDB's HTTP SQL interface column types) and is already used internally, e.g. in `Cursor._convert_rows()`:
```python
def _convert_rows(self):
if not ("col_types" in self._result and self._result["col_types"]):
raise ValueError(...)
types = self.result["col_types"]
converters = [self.converter.get(type) for type in types]
...
```
and `converter.py` already has a complete, documented mapping from these wire type codes to a `DataType` enum (`TIMESTAMP_WITH_TZ = 11`, `TIMESTAMP_WITHOUT_TZ = 15`, etc.) — so the information isn't missing, it's just not propagated into the public `description` property.
Why this matters
`type_code` is part of the standard DB-API 2.0 `description` contract (PEP 249). A consumer that only has a `Cursor` object (e.g. a driver-agnostic tool built against SQLAlchemy's cursor/dialect layer, or any generic DB-API client) has no supported way to find out a column's CrateDB type without either enabling a `Converter` (which changes value representation, not just exposing the type) or reaching into the private `cursor._result["col_types"]` attribute directly, which isn't part of the public API and could change without notice.
We actually hit this downstream in Apache Superset: `CrateEngineSpec.fetch_data()` has to read `cursor._result.get("col_types", [])` directly to tell timestamp columns apart from plain numeric ones, specifically because `cursor.description`'s `type_code` is always `None`:
https://github.com/apache/superset/blob/master/superset/db_engine_specs/crate.py#L98-L123
Suggested fix
In `Cursor.description`, populate the `type_code` slot (index 1 of the 7-tuple) from `self._result["col_types"]` (resolved through the existing `DataType` enum / `_resolve()` helper in `converter.py`) instead of hardcoding `None`, when `col_types` is available. This would bring `description` in line with the PEP 249 contract without needing a `Converter` to be configured, and let consumers stop reaching into `cursor._result` directly.
Environment
- crate-python: current `main` (same code present going back through recent tags)
- Verified by reading `src/crate/client/cursor.py` and `src/crate/client/converter.py` directly, cross-checked against the CrateDB HTTP SQL docs' column-types table.
- Lingua principale
- Python
- Stelle
- 85
- Fork
- 35
- Merge medio
- 2g 13h
- PR unite (30g)
- 2
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di crate/crate-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
crate/crate-python#794 · 2 commenti ·
-
Allow `connect()` (again) while the server is not respondingForse già presa @florinutz l’ha presa 19 giorni fa. Apertaenhancement
crate/crate-python#833 · 1 assegnatario ·
-
NUMERIC reads: full digits arrive, the decode drops themForse già presa @aminghadersohi l’ha presa 11 giorni fa. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
crate/crate-python#826 · 1 commento ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
crate/crate-python#751 · 7 commenti ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
crate/crate-python#729 · 1 commento ·
Tutte le issue di crate/crate-python
Issue simili
-
changelog investigate
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ramnes/notion-sdk-py#409 ·
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
lindicaphxag-tech/kaggle#28 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
BSData/horus-heresy-3rd-edition#3211 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
bug tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno