bigquery-derive: reject ambiguous and duplicate #[bigquery(...)] attributes at compile time

Abierto
#7,450 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

Start with src/bigquery-derive/src/lib.rs, especially get_field_name, derive_from_row_impl, and derive_from_sql_impl, then read the proc-macro guidance in doc/contributor/howto-guide-handwritten-client-api.md. Add unit tests there for duplicate resolved names, duplicate rename options across and within attributes, and unsupported container attributes; done when each case produces a spanned compile-time error.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

api: bigquery priority: p2 type: bug
Summary

google-cloud-bigquery-derive (#[derive(FromRow)] and #[derive(FromSql)]) silently accepts ambiguous and invalid #[bigquery(...)] attribute configurations instead of rejecting them with compile-time errors.

Because rejecting input that previously compiled is a breaking change to accepted macro input under the proc-macro compatibility policy (src/bigquery-derive/src/lib.rs), fixing these validation gaps before google-cloud-bigquery 1.0.0 is released (#7424) avoids requiring a major bump of google-cloud-bigquery later.

Problem Details

Per doc/contributor/howto-guide-handwritten-client-api.md:

Ambiguous input (for example, two fields mapping to the same property name after flattening) is an error, never resolved silently.

Currently in src/bigquery-derive/src/lib.rs:

  1. Duplicate target column / STRUCT field names compile silently and exhibit transport-dependent runtime behavior:
    • derive_from_row_impl and derive_from_sql_impl resolve each named field's column/field name independently without checking for duplicates across the struct.
    • For example:
      #[derive(FromRow)]
      struct AmbiguousRow {
          col: Option<String>,
          #[bigquery(rename = "col")]
          other: Option<String>,
      }
      
      (or two fields both marked #[bigquery(rename = "same")], or r#type colliding with #[bigquery(rename = "type")]).
    • At runtime, FromRow emits two row.take("col")? calls:
      • On JSON-backed rows (RowInner::Json in src/bigquery/src/query/row.rs), the first take replaces cell "col" with SqlValueInner::Null, so other silently receives None (or fails with ConvertError::NotNull for non-optional types).
      • On Arrow-backed rows (RowInner::Arrow in src/bigquery/src/query/row.rs), take reads from the RecordBatch without mutating it, so both col and other receive "col"'s value.
    • FromSql (SqlValue::take) has the same discrepancy between SqlValueInner::Struct (replaces slot with Null) and SqlValueInner::Arrow (reads without mutating).
  2. Multiple #[bigquery(...)] attributes on the same field short-circuit after the first rename:
    • In get_field_name (src/bigquery-derive/src/lib.rs), if let Some(name) = renamed { return Ok(name); } returns inside the for attr in &field.attrs loop.
    • A second #[bigquery(rename = "...")] on the same field is silently ignored instead of reporting a duplicate rename error, and a subsequent invalid attribute (e.g., #[bigquery(rename = "a")] #[bigquery(typo = "b")]) is never parsed at all.
  3. Duplicate rename options inside a single attribute overwrite silently:
    • #[bigquery(rename = "a", rename = "b")] overwrites renamed = Some(lit.value()) without checking if rename was already specified, silently using "b".
  4. Container-level #[bigquery(...)] attributes on structs are silently ignored:
    • Neither derive_from_row_impl nor derive_from_sql_impl inspects input.attrs, so unsupported container attributes such as #[bigquery(rename_all = "camelCase")] on a struct compile without error and have no effect.
Expected Behavior
  • Reject structs where two or more fields resolve to the same BigQuery column / STRUCT field name with a spanned syn::Error.
  • Inspect all #[bigquery(...)] attributes on every field and reject duplicate rename options (whether in one #[bigquery(rename = "a", rename = "b")] list or across multiple #[bigquery(...)] attributes on the same field).
  • Reject #[bigquery(...)] attributes placed on the container (struct/enum/union) itself until/unless container options are explicitly supported.
  • Add unit tests in src/bigquery-derive/src/lib.rs covering each error case, and take a breaking version bump on google-cloud-bigquery-derive if needed per the compatibility policy.
Lenguaje dominante
Rust
Estrellas
972
Forks
163
Merge medio
1 d 9 h
PR fusionados (30 d)
176

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de googleapis/google-cloud-rust

Todos los issues de googleapis/google-cloud-rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.