DATE_ADD/DATE_SUB with a single argument raises AttributeError (BigQuery, MySQL, Doris, StarRocks)

Aperta
#9,103 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@akchhayasharma ci sta già lavorando.

Dal 15/11/2026.

  • #9105 di @akchhayasharma — aperta

Valutazione

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

Direzione di ricerca

Start at build_date_delta_with_interval in the dialect module, which returns None when fewer than two args are passed, then follow it into Parser.validate_expression in parser.py where the None is dereferenced. Reproduce with sqlglot.parse_one("SELECT DATE_ADD(x)", read="bigquery") and compare against the DuckDB path that already raises a clean ParseError. Done means every listed dialect registration raises ParseError instead of AttributeError, with a test per dialect in the corresponding tests/dialects suite. Note an open pull request (#9105) already targets this, so coordinate before starting.

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

Descrizione

Fully reproducible code snippet

import sqlglot

sqlglot.parse_one("SELECT DATE_ADD(x)", read="bigquery")
# AttributeError: 'NoneType' object has no attribute 'error_messages'

The same applies to DATE_SUB, DATETIME_ADD/SUB, TIME_ADD/SUB and TIMESTAMP_ADD/SUB in BigQuery, DATE_ADD/DATE_SUB in MySQL, and the Doris/StarRocks registrations of the same builder.

Expected

A ParseError. The same input in DuckDB raises a clean ParseError; BigQuery DATE_DIFF(x) raises ParseError; and BigQuery DATE_SUB(x, 1) raises "ParseError: INTERVAL expression expected but got '1'".

Actual

The dialect builder build_date_delta_with_interval returns None when len(args) < 2, and Parser.validate_expression then dereferences None.error_messages (in parser.py), producing the AttributeError.

Checked against main at commit b294f7f.

Official Documentation

BigQuery DATE_ADD requires a date expression and an INTERVAL: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_add
MySQL DATE_ADD: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

Found by property-based testing (a no-crash property over mutated inputs drawn from sqlglot's own test corpus).

Lingua principale
Python
Stelle
9.8k
Fork
1.4k
Merge medio
13h 19m
PR unite (30g)
243

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 tobymao/sqlglot

Tutte le issue di tobymao/sqlglot

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.