[Bug?] Document Tag Reading Values with Numeric Keys or Spaces

Hi,

I’m trying to refactor some code to take advantage of the deep reading of objects in 8.1, as stated here:
docs

I have found that this syntax only works for documents that have alpha numeric keys.

See example below:
The memory tag ([Development]DocTag) has a value as follows:

  "value": {
    "data": {
      "alphaNumeric1": "alpha numeric 1",
      "1": "this key is a number",
      "has spaces": "this key has spaces"
    }
  }

I can only read the keys that are alphanumeric. Any keys that are a number or contain spaces result in a malformed path exception.

Results (with. [key.deepKey] notation:

print system.tag.readBlocking(["[Development]DocTag['data']"])
>>> [[{alphaNumeric1=alpha numeric 1, 1=this key is a number, has spaces=this key has spaces}, Good, Mon Nov 23 10:19:40 CAT 2020 (1606119580207)]]

print system.tag.readBlocking(["[Development]DocTag['data.alphaNumeric1']"])
>>> [[alpha numeric 1, Good, Mon Nov 23 10:19:40 CAT 2020 (1606119580207)]]

print system.tag.readBlocking(["[Development]DocTag['data.1']"])
>>> [[null, Error_Exception("Malformed path: data.1"), Mon Nov 23 10:31:32 CAT 2020 (1606120292149)]]

print system.tag.readBlocking(["[Development]DocTag['data.has spaces']"])
>>> [[null, Error_Exception("Malformed path: data.has spaces"), Mon Nov 23 10:31:32 CAT 2020 (1606120292153)]]

Same with [‘key’][‘deepkey’] notation:

print system.tag.readBlocking(["[Development]DocTag['data']"])
>>> [[{alphaNumeric1=alpha numeric 1, 1=this key is a number, has spaces=this key has spaces}, Good, Mon Nov 23 10:19:40 CAT 2020 (1606119580207)]]

print system.tag.readBlocking(["[Development]DocTag['data']['alphaNumeric1']"])
>>> [[null, Error_Exception("Malformed path: data']['alphaNumeric1"), Mon Nov 23 10:36:42 CAT 2020 (1606120602222)]]

print system.tag.readBlocking(["[Development]DocTag['data']['1']"])
>>> [[null, Error_Exception("Malformed path: data']['1"), Mon Nov 23 10:36:42 CAT 2020 (1606120602226)]]

print system.tag.readBlocking(["[Development]DocTag['data']['has spaces']"])
>>> [[null, Error_Exception("Malformed path: data']['has spaces"), Mon Nov 23 10:36:42 CAT 2020 (1606120602229)]]

Is this a bug or am I doing something wrong?

Regards,
Deon

Seems pretty normal to me, from a language perspective. While not a programming language per-se, syntax like that is generally implemented with parsers for programming languages. Which means you should only expect keys that would be acceptable identifiers in a programming language to work. Whether that is IA’s intent or not.

It is tempting to use Ignition’s tolerance for any old string in the names of various items in its platform, but your life will be much simpler if you treat all internal names as if they are java/jython/python variable names, and follow those rules. Consider including this in your refactoring.

1 Like

As a workaround, you could read the entire tag, and then do the data extraction ‘manually’ - I’m pretty confident something like this would work (you will have to use the [0] to retrieve the first element out of the result list - not the prettiest syntax ever:

print system.tag.readBlocking(["[Development]DocTag"])[0]['data']['1']

That is exactly what I’ve been doing up to know. It just feels unnecessarily heavy to read the whole document, which is a huge database cache, only to extract a single value.

The keys in the document tag is actually the database primary key. I can do something funny, like make the key id1234, where 1234 is the PK.

Probably best to avoid non complaint keys to start with, as Phil said.

Well, I can say that reading the whole document to extract the specified key is very likely also what we’re doing - I’d have to dive into the code to confirm, but I don’t think there’s any mechanism to deliver a true partial value like that.