[2020.20020 - x64 - Win10] TDJSON does not work (fully) with built-in parameters

Hello,

I’ve been playing with TDJSON for a while now (more than a year I believe) for a personal project. I went back to testing it every build since early 2019, and it seems that it is still not fully bug-free.

In the release notes of 2020.20020, it is advertised that:

TDJSON updated and bugs fixed.

  • All functions now work with built-in parameters.
  • Added a deserializer TDData function to TDJSON.

Unfortunately, not all functions work with built-in parameters.

The main problem seems to be with the extraAttrs argument (of any function).

For example, calling the following few lines on COMPs or Pars will work just fine:
TDJ.opToJSONOp(comp, forceAttrLists=True, includeCustomPages=True, includeBuiltInPages=True)
or the straightforward
TDJ.parameterToJSONPar(parameter, forceAttrLists=True)

Now, calling the followings
TDJ.opToJSONOp(n, extraAttrs=ATTR_LIST, forceAttrLists=True, includeCustomPages=True, includeBuiltInPages=True)
or TDJ.parameterToJSONPar(parameter, extraAttrs=ATTR_LIST, forceAttrLists=True)

where ATTR_LIST is the following constant string-array, of all the attributes that I know of:

ATTR_LIST = [
	'valid',
	'val',
	'expr',
	'exportOP',
	'exportSource',
	'bindMaster',
	'tuplet',
	'prevMode',
	'owner',
	'bindExpr',
	'bindReferences',
	'index',
	'vecIndex',
	'name',
	'label',
	'startSection',
	'displayOnly',
	'readOnly',
	'tupletName',
	'min',
	'max'
	'clampMin',
	'clampMax',
	'default',
	'defaultExpr',
	'normMin',
	'normMax'
	'normVal',
	'enable',
	'order',
	'page',
	'password',
	'mode',
	'menuNames',
	'menuLabels',
	'menuIndex',
	'menuSource'
	]

will cause an exception:

Traceback (most recent call last):
  File "</BananaGit/text2:op('/BananaGit/text2').run()>", line 1
td.Error: File "/BananaGit/text2", line 1
  File "/BananaGit/BananaGitExt", line 101, in GetOpJson
  File "/sys/TDModules/TDJSON", line 264, in opToJSONOp
  File "/sys/TDModules/TDJSON", line 245, in pageToJSONDict
  File "/sys/TDModules/TDJSON", line 185, in parameterToJSONPar
td.Error: Custom parameter expected. Value:type:Par name:extension1 owner:/TEST_MANAGER value: Type:<class 'td.Par'>.
Results of run operation resulted in exception.

Passing no extra attributes doesn’t cause any issue. Passing only a handful of attributes such as [‘val’, ‘owner’, ‘label’] will work fine. My guess is that either one or multiple of those extra attributes are not available (or protected) on builtin parameters.

So:

  1. Could we get the list of safe attributes for Built-in parameters ?
  2. Could we get the list of safe attributes for Custom parameters ?
  3. Would it be possible to add an argument such as quietlyFail=True where if an attribute that cannot be returned is provided, then it will just be skipped ?

Thank you for your time,
Michel

+1 this could make so many killer tools but seems like you can hit a bunch of walls if you get too deep.

1 Like

Thanks for report! This is caused by an incorrect exception being thrown by TD when you try to look at the order attribute of non-custom parameters. Will be fixed in future versions.

re 1 & 2: This is an engine bug, so once fixed all par attributes (built in and custom) will be safe. I tested on literally everything, using dir(parameter).

re 3: It is actually already supposed to be quietly failing, but because TD throws an incorrect Python exception during the check itself, it is erroring out early.

It’s tricky to convert TD data to JSON automatically using introspection. Your feedback is greatly appreciated.

TDJSON.zip (4.8 KB)

Here is a TDJSON that should work for you in the meantime. Feel free to try to break it :slight_smile:

Hey Ivan,

Gave it a quick try and it works so far, thanks !

Michel

Found a bug in thereTDJSON.zip (4.8 KB)

Can you confirm new official works for you?

Hey Ivan,

So far in my test patch, it does seem to work yeah :slight_smile:

I’m gonna try and find some time ASAP to dig further in that project that will fully rely on TDJSON. I’ll report back soon.

Thanks for the hard work !

Michel

I added some insurance in the code, but the main problem was that formerly certain attributes were only available on custom parameters. That should be changed now so that you can access the same info on both custom and builtin parameters

1 Like