builder: Oracle Merge JSON_TABLE infers VARCHAR2(4000) by char length instead of UTF-8 bytes and omits ERROR ON ERROR

Aperta Adatta ai principianti
#946 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, sql

Direzione di ricerca

Inizia da sqlspec/builder/_merge.py, soprattutto da _create_oracle_json_source() e _infer_oracle_type(), poi confronta la gestione del limite di byte in sqlspec/adapters/oracledb/core.py. Controlla la proiezione Oracle JSON_TABLE e l’SQL generato per stringhe multibyte che superano i 4.000 byte UTF-8 e per gli errori di conversione. Il risultato atteso è che questi valori vengano inferiti come CLOB e che JSON_TABLE emetta ERROR ON ERROR.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Summary

The Oracle Merge builder's JSON_TABLE source generator infers VARCHAR2(4000) vs CLOB using Python character length (len(str(value))) instead of UTF-8 byte length, and omits ERROR ON ERROR on JSON_TABLE. Under Oracle's default NLS_LENGTH_SEMANTICS=BYTE, multi-byte UTF-8 strings between 2,001 and 4,000 characters exceed 4,000 bytes and are silently coerced to NULL during MERGE.

Details

  1. Character count vs. UTF-8 byte length (sqlspec/builder/_merge.py:375, 419-428):

    • _create_oracle_json_source() compares len(str(value)) > len(str(existing)) (_merge.py:375) and _infer_oracle_type() checks len(str(value)) > 4000 (_merge.py:426).
    • This is inconsistent with coerce_large_parameters_sync() / _string_exceeds_byte_limit() in sqlspec/adapters/oracledb/core.py, which correctly checks UTF-8 encoded byte length against varchar2_byte_limit=4000.
    • A 2,500-character multi-byte string (e.g. "é" * 2500, 5,000 UTF-8 bytes) is inferred as VARCHAR2(4000) instead of CLOB.
  2. Silent NULL ON ERROR default on JSON_TABLE (sqlspec/builder/_merge.py:380-397):

    • exp.JSONTable(...) emits JSON_TABLE(:json_payload, '$[*]' COLUMNS (...)) without an ERROR ON ERROR clause.
    • Oracle JSON_TABLE defaults to NULL ON ERROR, so any value overflowing VARCHAR2(4000) or failing JSON/type conversion is silently projected as NULL rather than raising an ORA error.

Reproduction (sqlspec==0.74.2)

from sqlspec.builder import Merge

notes = "é" * 2500
assert len(notes) == 2500
assert len(notes.encode("utf-8")) == 5000

stmt = (
    Merge(dialect="oracle")
    .into("target", alias="t")
    .using([{"id": 1, "notes": notes}], alias="s")
    .on("t.id = s.id")
    .when_matched_then_update(notes="s.notes")
    .when_not_matched_then_insert(id="s.id", notes="s.notes")
    .build()
)
print(stmt.sql)
# Emits:
# FROM JSON_TABLE(:json_payload, '$[*]' COLUMNS(id NUMBER PATH '$.id', notes VARCHAR2(4000) PATH '$.notes'))

Expected Behavior

  • Measure UTF-8 byte length (len(str(value).encode("utf-8"))) in _create_oracle_json_source() sample selection and _infer_oracle_type() so strings exceeding 4,000 UTF-8 bytes project as CLOB.
  • Emit ERROR ON ERROR in Oracle JSON_TABLE projections so overflow or type conversion errors fail explicitly instead of silently writing NULL.
Lingua principale
Python
Stelle
110
Fork
11
Merge medio
19h 9m
PR unite (30g)
37

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di litestar-org/sqlspec

Tutte le issue di litestar-org/sqlspec

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.