Skip to content

fix: Prevent "null" identifier collisions from malformed drink JSON - #339

Merged
richardthe3rd merged 3 commits into
mainfrom
copilot/fix-missing-id-name-in-json
May 27, 2026
Merged

fix: Prevent "null" identifier collisions from malformed drink JSON#339
richardthe3rd merged 3 commits into
mainfrom
copilot/fix-missing-id-name-in-json

Conversation

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor

Producer.fromJson and Product.fromJson were coercing nullable id/name fields with .toString(), which turned missing values into the literal "null". That allowed multiple bad records to share the same ID, causing key collisions in lists and incorrect ID-based lookups.

  • Model parsing hardening (lib/models/drink.dart)

    • Replaced nullable .toString() coercion with nullable string casts + empty fallback:
      • id: (json['id'] as String?) ?? ''
      • name: (json['name'] as String?) ?? ''
    • Prevents accidental "null" string IDs/names.
  • Repository-layer record filtering (lib/services/beer_api_service.dart)

    • In parseProducers, now skips:
      • producers with empty producer.id
      • products with empty product.id
    • Keeps invalid upstream records from entering app state and avoids downstream key/lookup corruption.
  • Regression coverage

    • Added model tests for null id/name parsing to ''.
    • Added API parsing tests to verify products/producers with missing IDs are excluded.
return Product(
  id: (json['id'] as String?) ?? '',
  name: (json['name'] as String?) ?? '',
  // ...
);

// parseProducers
if (producer.id.isEmpty) continue;
for (final product in producer.products) {
  if (product.id.isEmpty) continue;
  drinks.add(Drink(product: product, producer: producer, festivalId: festivalId));
}

Copilot AI changed the title [WIP] Fix missing id/name in JSON parsed as "null" string Prevent "null" identifier collisions from malformed drink JSON May 27, 2026
Copilot AI requested a review from richardthe3rd May 27, 2026 10:22
@richardthe3rd
richardthe3rd marked this pull request as ready for review May 27, 2026 10:37
Copilot AI review requested due to automatic review settings May 27, 2026 10:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens drink JSON parsing and downstream API parsing to prevent key collisions and incorrect lookups when upstream records have missing id/name fields (previously coerced into the literal "null").

Changes:

  • Update Producer.fromJson / Product.fromJson to avoid .toString() on nullable id/name, mapping missing values to ''.
  • Filter invalid records in BeerApiService.parseProducers by skipping producers/products with empty IDs.
  • Add regression tests covering null ID/name parsing and API filtering behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/models/drink.dart Adjusts model JSON parsing for id/name to avoid "null" and reduce collisions.
lib/services/beer_api_service.dart Skips producers/products with empty IDs when flattening to Drink list.
test/models_test.dart Adds regression tests for null id/name mapping to ''.
test/beer_api_service_test.dart Adds tests ensuring API parsing skips invalid producers/products missing IDs.

Comment thread lib/models/drink.dart
Comment on lines 29 to 32
return Producer(
id: json['id'].toString(),
name: json['name'].toString(),
id: (json['id'] as String?) ?? '',
name: (json['name'] as String?) ?? '',
location: (json['location'] ?? '').toString(),
Comment thread lib/models/drink.dart
Comment on lines 141 to 144
return Product(
id: json['id'].toString(),
name: json['name'].toString(),
id: (json['id'] as String?) ?? '',
name: (json['name'] as String?) ?? '',
category: (json['category'] ?? 'beer').toString(),
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Cloudflare Pages Preview

Your preview deployment is ready!

Preview URL: https://copilot-fix-missing-id-name.staging-cambeerfestival.pages.dev

This preview will be automatically updated when you push new commits to this PR.

@richardthe3rd

Copy link
Copy Markdown
Owner

@copilot fix pr lint failure

Copilot AI commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix pr lint failure

I checked the failing PR Lint run: it’s failing the semantic-title check, not code lint. Please rename the PR title to a Conventional Commits format, for example:

fix: prevent "null" identifier collisions from malformed drink JSON

After retitling, PR Lint should pass.

@richardthe3rd richardthe3rd changed the title Prevent "null" identifier collisions from malformed drink JSON fix: Prevent "null" identifier collisions from malformed drink JSON May 27, 2026
@richardthe3rd
richardthe3rd merged commit fc3fac8 into main May 27, 2026
15 of 17 checks passed
This was referenced May 27, 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.

Missing id/name in JSON parsed as "null" string

3 participants