Skip to content

Spark does not escape nested function types #105

Open
@briankariuki

Description

@briankariuki

Describe the bug
I have an entity defined with a schema option (i.e news) that is a keyword list with its key types defined by keys. One of the fields (publication_date) may be a function that will return a string for the field. But when I compile this code, I get an error

Error: cannot inject attribute @urls into function/macro because cannot escape #Function<>

It does compile when I remove {:fun, [:map], :string} from the list of type options for publication_date. It does escape the function correctly for the :path option

@urls %Spark.Dsl.Entity{
    name: :url,
    target: AshSitemap.Url,
    examples: [
      "url 'index.html', priority: 0.5"
    ],
    schema: [
      path: [
        type: {
          :or,
          [:string, {:fun, [:map], :string}]
        },
        required: true
      ],
      priority: [type: :float, required: false],
      news: [
        type: :non_empty_keyword_list,
        keys: [
          publication: [
            type: :string,
            required: true
          ],
          publication_date: [
            type: {
              :or,
              [:string, :atom, {:fun, [:map], :string}]
            },
            required: true
          ],
          title: [
            type: {
              :or,
              [:string, :atom]
            },
            required: true
          ],
          keywords: [
            type: {:list, :string},
            required: true
          ]
        ],
        required: false
      ]
    ],
    args: [:path]
  }

To Reproduce
Use the above urls entity as an example

Expected behavior
I expected spark to parse the types of the publication_date correctly

Runtime

  • Elixir version 1.17
  • Erlang version 26.2.5
  • OS MacOS 14.3.1
  • Spark version 2.2.10
  • any related extension versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Soon

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions