emrichen icon indicating copy to clipboard operation
emrichen copied to clipboard

`!Lookup` does not enrich on the fly

Open japsu opened this issue 6 years ago • 3 comments

Template:

!Defaults
x:
  y: 5
z: !Var x
---
workie: !Lookup x.y
no_workie: !Lookup z.y

Expected output:

workie: 5
no_workie: 5

Actual output:

Traceback (most recent call last):
  File "/usr/local/bin/emrichen", line 11, in <module>
    load_entry_point('emrichen', 'console_scripts', 'emrichen')()
  File "/Users/sapaj1/Hobby/emrichen/emrichen/__main__.py", line 111, in main
    output = template.render(context, format=args.output_format)
  File "/Users/sapaj1/Hobby/emrichen/emrichen/template.py", line 22, in render
    enriched = self.enrich(context)
  File "/Users/sapaj1/Hobby/emrichen/emrichen/template.py", line 19, in enrich
    return context.enrich(self.template)
  File "/Users/sapaj1/Hobby/emrichen/emrichen/context.py", line 37, in enrich
    item = self.enrich(item)
  File "/Users/sapaj1/Hobby/emrichen/emrichen/context.py", line 30, in enrich
    val = self.enrich(val)
  File "/Users/sapaj1/Hobby/emrichen/emrichen/context.py", line 21, in enrich
    return self.enrich(value.enrich(self))
  File "/Users/sapaj1/Hobby/emrichen/emrichen/tags/lookup.py", line 19, in enrich
    raise KeyError(f'{self}: no matches for {self.data}')
KeyError: "Lookup('z.y'): no matches for z.y"

japsu avatar Aug 13 '18 21:08 japsu

I guess we'll have to augment the JSONPath resolver to maybe_enrich when it traverses.

akx avatar Aug 14 '18 05:08 akx

Yeah, the JSONPath resolver isn't that easy to hack to do this, unfortunately.

akx avatar Aug 17 '18 08:08 akx

I had a similar issue when using With, I wanted vars to be enriched:

    rows: !Loop
      over: !Var subareaRows
      as: row
      template: !Merge
        - context: !Var parentContext
          color: !Lookup row.color
        - !With
          template:
            geoid: !Var geoid
          vars: !LookupGeometry
            path: !Var datasetUrl
            context: !Var parentContext
            lookup:
              subarea_name: !Lookup row.name

zbyte64 avatar Oct 13 '21 18:10 zbyte64