Skip to content

feat: Replace from_avro_datum* functions with GenericDatumReader - #496

Merged
Kriskras99 merged 2 commits into
mainfrom
feat/generic_datum_reader
Mar 5, 2026
Merged

Kriskras99 merged 2 commits into
mainfrom
feat/generic_datum_reader

Conversation

@Kriskras99

Copy link
Copy Markdown
Contributor

The from_avro_datum* functions have been deprecated and point to GenericDatumReader.

I've also made the reader module public so that users need to import GenericDatumReader from reader::datum. This should further discourage users from using this.

I also want to this for the to_avro_datum* functions, but I'll first make a PR making writer.rs a directory module.

@Kriskras99
Kriskras99 force-pushed the feat/generic_datum_reader branch from 83ffedb to 07a261f Compare March 5, 2026 07:22
@Kriskras99

Copy link
Copy Markdown
Contributor Author

Merge conflicts resolved

Comment thread avro/src/reader/datum.rs Resolved
Comment thread avro/src/reader/datum.rs Resolved
Comment thread avro/src/reader/datum.rs Resolved
Comment thread avro/src/reader/datum.rs Resolved
Comment thread avro/src/reader/datum.rs Resolved
@Kriskras99
Kriskras99 merged commit 927847a into main Mar 5, 2026
21 checks passed
@Kriskras99
Kriskras99 deleted the feat/generic_datum_reader branch March 5, 2026 10:09
@martin-g martin-g added this to the 0.22.0 milestone Mar 5, 2026
martin-g pushed a commit that referenced this pull request Jun 8, 2026
…pe-ref (#547) (#548)

* fix(schema): return Err instead of panicking on invalid name/alias/type-ref

`Schema::parse_str` panicked on schema JSON whose alias, type reference, or
nested type name is not a valid Avro identifier, because three sites in
`schema::parser` called `Name::new(..).unwrap()` / `Alias::new(..).unwrap()`
on values that already return `AvroResult`. Since `parse_str` is a public
`Result`-returning API, callers cannot guard against the unwind, so parsing
untrusted schema JSON was a DoS. This is the sibling of the `Name::parse`
fix in #496.

- `get_already_seen_schema`: an unparseable type name cannot match an
  already-seen schema, so return `None` (`.ok()?`) rather than unwrap.
- `fix_aliases_namespace`: return `AvroResult<Aliases>` and propagate; an
  invalid alias is a schema error (`?` added at the three call sites).
- `get_schema_type_name`: fall back to the enclosing name (`unwrap_or(name)`),
  matching the existing `_ => name` arm.

Adds a regression test (tests/avro-rs-547.rs) covering invalid aliases,
nested names and type references, plus a positive case ensuring valid
aliases still parse.

Fixes #547

Signed-off-by: youichi-uda <[email protected]>

* address review: avoid clones in fix_aliases_namespace; propagate in get_schema_type_name

- fix_aliases_namespace: use `contains('.')` and pass `&str` / `&format!(..)`
  directly to `Alias::new`, dropping the intermediate `qualified` String and
  the per-alias clones.
- get_schema_type_name: return `AvroResult<Name>` and propagate the
  validation error (callers updated with `?`) instead of silently falling
  back to the enclosing name on an invalid nested `type` name.

Signed-off-by: youichi-uda <[email protected]>

---------

Signed-off-by: youichi-uda <[email protected]>
Co-authored-by: youichi-uda <[email protected]>
@Kriskras99 Kriskras99 mentioned this pull request Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants