Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [YAML] args is unavailable for feature's exclude_when #1169

Open
zstadler opened this issue Feb 6, 2025 · 3 comments
Open

[BUG] [YAML] args is unavailable for feature's exclude_when #1169

zstadler opened this issue Feb 6, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@zstadler
Copy link
Contributor

zstadler commented Feb 6, 2025

Describe the bug
An expression that uses args in a feature's exclude_when or include_when causes an exception

To Reproduce

  1. Save the modified manholes.yml
schema_name: Manhole covers
schema_description: Manhole covers
attribution: <a href="https://www.openstreetmap.org/copyright" target="_blank">&copy;
  OpenStreetMap contributors</a>
sources:
  osm:
    type: osm
    url: geofabrik:rhode-island
layers:
- id: manhole
  features:
  - source:
    - osm
    geometry: point
    min_zoom: 14
    include_when:
      man_made: manhole
    exclude_when:
      - '${ args.getOrDefault("only_layers", "manhole") != "manhole" }'
    attributes:
    - key: man_made
    - key: manhole
    - key: operator
    - key: ref
  1. run
docker run --rm -v "$(pwd):/w" -w /w ghcr.io/onthegomap/planetiler manhoe.yaml --only_layers=manhole --output manhole.pmtiles --download |& head -200
  1. See the following exception:
0:00:28 ERR [osm_pass2:process] - Error processing OSM Node 4
com.onthegomap.planetiler.custommap.expression.EvaluationException: Error evaluating script: Error evaluating script ' args.getOrDefault("only_layers", "transportation") != "transportation" '
        at com.onthegomap.planetiler.custommap.expression.ConfigExpressionScript.apply(ConfigExpressionScript.java:127)
        at com.onthegomap.planetiler.custommap.expression.BooleanExpressionScript.evaluate(BooleanExpressionScript.java:33)
        at com.onthegomap.planetiler.expression.Expression$Not.evaluate(Expression.java:371)
        at com.onthegomap.planetiler.expression.Expression$And.evaluate(Expression.java:280)
        at com.onthegomap.planetiler.expression.MultiExpression$KeyIndex.visitExpressions(MultiExpression.java:307)
        at com.onthegomap.planetiler.expression.MultiExpression$KeyIndex.getMatchesWithTriggers(MultiExpression.java:329)
        at com.onthegomap.planetiler.expression.MultiExpression$GeometryTypeIndex.getMatchesWithTriggers(MultiExpression.java:371)
        at com.onthegomap.planetiler.expression.MultiExpression$StringFieldIndex.getMatchesWithTriggers(MultiExpression.java:433)
        at com.onthegomap.planetiler.custommap.ConfiguredProfile.processFeature(ConfiguredProfile.java:73)
        at com.onthegomap.planetiler.reader.osm.OsmReader.render(OsmReader.java:471)
        at com.onthegomap.planetiler.reader.osm.OsmReader.lambda$pass2$7(OsmReader.java:363)
        at com.onthegomap.planetiler.worker.WorkerPipeline$Builder.lambda$addWorker$0(WorkerPipeline.java:249)
        at com.onthegomap.planetiler.worker.Worker.lambda$new$0(Worker.java:41)
        at com.onthegomap.planetiler.worker.Worker.lambda$new$1(Worker.java:68)
        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1848)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1575)
Caused by: org.projectnessie.cel.tools.ScriptExecutionException: undeclared reference to 'id: 1, attributes: [id: 1, names: [args]]' (in container '')
        at org.projectnessie.cel.tools.Script.evaluate(Script.java:59)
        at org.projectnessie.cel.tools.Script.execute(Script.java:41)
        at com.onthegomap.planetiler.custommap.expression.ConfigExpressionScript.apply(ConfigExpressionScript.java:125)
        ... 17 more

Expected behavior
The expression would be accepted in a feature's exclude_when and include_when, just as it is accepted in attribute's value:

    attributes:
    - key: exclude_manhole
      value: '${ args.getOrDefault("only_layers", "manhole") != "manhole" }'

Environment (please complete the following information):

  • Hardware: Lenovo Legion
  • OS: Windows 11 Pro + Docker version 27.4.0, build bde2b89
  • Java version and distribution: As used by ghcr.io/onthegomap/planetiler
  • Maven version: As used by ghcr.io/onthegomap/planetiler

Additional context
Related to #1168

@zstadler zstadler added the bug Something isn't working label Feb 6, 2025
@msbarry
Copy link
Contributor

msbarry commented Feb 7, 2025

Thanks for the report, a couple of problems here:

  1. only_layers/exclude_layers should work automatically without needing to add custom handling for the arg in yaml
  2. you should be able to reference args in an expression at that location
  3. that expression should have been statically evaluated ahead of time so it just turned into exclude_when: [false}

@msbarry
Copy link
Contributor

msbarry commented Feb 7, 2025

Ahh I see you opened #1168 for problem (1) 👍

@zstadler
Copy link
Contributor Author

zstadler commented Feb 7, 2025

Ahh I see you opened #1168 for problem (1) 👍

Yes. I've considered problem (1) a feature request. When trying to work around it, I've found problem (2) which I considered a bug. That's why each got a separate GitHub issue. Problem (3) is an implementation issue I know nothing about 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants