Skip to content

Can't parse: JSON recipe that has a PropertyValue as a recipeIngredient #540

Description

@JonathanHarford

Describe the bug
Recipya errors when given a JSON recipe that has a PropertyValue as a recipeIngredient:

panic: interface conversion: interface {} is map[string]interface {}, not string

goroutine 210 [running]:
github.com/reaper47/recipya/internal/models.(*Ingredients).UnmarshalJSON(0xc00090c528, {0xc00074010a, 0xc5, 0x276})
	/app/internal/models/schema-recipe.go:618 +0x36a
encoding/json.(*decodeState).array(0xc0000c2870, {0x13515c0?, 0xc00040a0a0?, 0x0?})
	/usr/local/go/src/encoding/json/decode.go:508 +0x3bb
encoding/json.(*decodeState).value(0xc0000c2870, {0x13515c0?, 0xc00040a0a0?, 0x10?})
	/usr/local/go/src/encoding/json/decode.go:365 +0x74
encoding/json.(*decodeState).object(0xc0000c2870, {0x13511c0?, 0xc00040a000?, 0x1c0026?})
	/usr/local/go/src/encoding/json/decode.go:762 +0xd71
encoding/json.(*decodeState).value(0xc0000c2870, {0x13511c0?, 0xc00040a000?, 0x473479?})
	/usr/local/go/src/encoding/json/decode.go:375 +0x3e
encoding/json.(*decodeState).unmarshal(0xc0000c2870, {0x13511c0?, 0xc00040a000?})
	/usr/local/go/src/encoding/json/decode.go:178 +0x11e
encoding/json.Unmarshal({0xc000740000, 0x23e, 0x380}, {0x13511c0, 0xc00040a000})
	/usr/local/go/src/encoding/json/decode.go:108 +0xf9
github.com/reaper47/recipya/internal/services.(*Files).extractJSONRecipes(0xc0000352e0, {0x7233b82d3f88, 0xc00090c330})
	/app/internal/services/files_apps.go:392 +0x1f4
github.com/reaper47/recipya/internal/services.(*Files).processJSON(0xc0000352e0, 0xc0002b6720)
	/app/internal/services/files_apps.go:52 +0x1ac
github.com/reaper47/recipya/internal/services.(*Files).ExtractRecipes.func2(0xc0002b6720)
	/app/internal/services/files.go:906 +0x207
created by github.com/reaper47/recipya/internal/services.(*Files).ExtractRecipes in goroutine 49
	/app/internal/services/files.go:894 +0xde

To Reproduce
Steps to reproduce the behavior:

  1. Go to /recipes/add
  2. Click on Import
  3. Provide a recipe that uses a PropertyValue as a recipeIngredient
  4. See error in logs

Expected behavior
Recipe is added successfully.

Screenshots
Image

Desktop (please complete the following information):

  • OS: Mac Intel
  • Browser Zen 1.16.4b (Firefox 143.0.4) (64-bit)
  • Version 1.16.4b

Additional context
I may have my recipya instance badly set up, but when the parsing fails, it shows as a websocket error and I get logged out!
Uploads OK:

{
  "@context": "https://schema.org",
  "@type": "Recipe",
  "name": "Dry Toast",
  "description": "When you can't keep anything down",
  "recipeYield": "1 servings",
  "prepTime": "PT3M",
  "totalTime": "PT3M",
  "recipeCategory": "sandwich",
  "recipeIngredient": ["1 slice whole wheat bread"],
  "recipeInstructions": [
    {
      "@type": "HowToStep",
      "text": "Toast for 2 minutes."
    }
  ]
}

Breaks:

{
  "@context": "https://schema.org",
  "@type": "Recipe",
  "name": "Dry Toast",
  "description": "When you can't keep anything down",
  "recipeYield": "1 servings",
  "prepTime": "PT3M",
  "totalTime": "PT3M",
  "recipeCategory": "sandwich",
  "recipeIngredient": [
    {
      "@type": "PropertyValue",
      "name": "whole wheat bread",
      "value": {
        "@type": "QuantitativeValue",
        "value": "1",
        "unitText": "slice"
      }
    }
  ],
  "recipeInstructions": [
    {
      "@type": "HowToStep",
      "text": "Toast for 2 minutes."
    }
  ]
}

This is closely related to #407
I'm filing this as a bug because Recipya claims to be able to import recipes that adhere to the Recipe Schema.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions