cursor.description's type_code is always None, even though col_types is already available internally
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Facilidade para iniciantes
- 72/100
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- Python
- Estrelas
- 85
- Forks
- 35
- Merge médio
- 2d 13h
- PRs com merge (30d)
- 2
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Sem modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de crate/crate-python
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
crate/crate-python#794 · 2 comentários ·
-
Allow `connect()` (again) while the server is not respondingTalvez já em andamento @florinutz assumiu há 27 dias. Abertaenhancement
crate/crate-python#833 · 1 responsável ·
-
NUMERIC reads: full digits arrive, the decode drops themTalvez já em andamento @aminghadersohi assumiu há 19 dias. Abertabug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
crate/crate-python#826 · 1 comentário ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
crate/crate-python#751 · 7 comentários ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
crate/crate-python#729 · 1 comentário ·
Todas as issues de crate/crate-python
Issues semelhantes
-
Workflow.schedule stops when a cron deadline passes before sleepTalvez já em andamento @HuaTNA assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
Mantenedores costumam responder em até 1 dia
-
[Bug] HiveDialect shares its colspecs dict with SQLAlchemy's DefaultDialect (python/pyhive)Talvez já em andamento @rusackas assumiu hoje. Aberta
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 80/100
apache/kyuubi#7786 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 80/100
Mantenedores costumam responder em até 1 dia
-
[20.0] hr_work_entry: Duration column of Export Time Entries is truncated to whole hoursTalvez já em andamento @odooaktiv assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
fix formatting of the sample database page of the docsTalvez já em andamento @Aaqibhafeezkhan assumiu hoje. Abertadocumentation good first issue help wanted
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 72/100
chaoss/CollectOSS#544 · 1 comentário ·
Mantenedores costumam responder em até 1 dia