Exclude fields on RECORD()

Hi there,

It would be useful to be able to ignore fields when using RECORD() mainly to avoid circular dependencies.

One example:

  • Column “template_data” is RECORD(rec, expand_refs=1)
  • Column “content1” is return tpl.substitute($template1, $template_data)
  • Column “content2” is return tpl.substitute($template2, $template_data)

Both content1 and content2 would have the following before the code above:

from string import Template
def tpl(template, data):
  return Template(template).substitute(data)

This example will crash the content fields as there will be a circular dependency as soon as you add either content1 or content2.

This is a barebones example where you would put the RECORD call inside the content columns, but on a more complex situation where template_data becomes more involved and duplication is less of an option… you’re screwed.

It would be useful for RECORD to accept an exclude_columns=[] so template_data would be RECORD(rec, expands_refs=1, exclude_columns=['content1', 'content2'])


Are you familiar with the PEEK function? It can help to prevent circular dependencies

I did not!

But it won’t solve my use case :frowning: as I would either end up with stale data on the PEEK call, or I would have no previous data to be returned to PEEK.

Not sure this really helps, but could an approach like this help?

from string import Template

def tpl(template, record):
  class R:
    def __getitem__(self, key):
      return getattr(record, key)
  return Template(template).substitute(R())

tpl("$A + $B + ...", rec)

That looks too convoluted, though original, also:

  1. Would not work properly on Refs. (expand_refs=1 above).
  2. Would not reduce the need to duplicate code as that would go into the content formulas, in which case you can just use RECORD(). The circular dependency appears when moving RECORD() out of the content cell (to template_data).

For now I am solving this by constructing template_data without RECORD with only what I need, but the Feature Request remains! :smiley: