etingof/pyasn1

Unwanted optional property is added while encoding.

daniel-leicht opened this issue · 1 comments

Hello dear pyasn1 maintainers,

I managed to solved some issues in my journey into using pyasn1 for MMS so far, but I hit a wall on this one:

Decoding seems fine, but when I'm trying to encode an object that has an optional property, the property is suddenly added to the object even tho I did not specify it.
For example, the property "listOfModifier" in the example bellow:

mms_pdu = MMSpdu()
confirmed_request = mms_pdu['confirmed-RequestPDU']
confirmed_request['invokeID'] = invoke_id_counter
invoke_id_counter += 1
confirmed_service_request = confirmed_request['confirmedServiceRequest']
confirmed_service_request['identify'] = None
print(mms_pdu)
print(decode(encode(mms_pdu, schema=MMSpdu), asn1Spec=MMSpdu().subtype())[0])

The printed result is:

MMSpdu:
 confirmed-RequestPDU=Confirmed_RequestPDU:
  invokeID=0
  confirmedServiceRequest=ConfirmedServiceRequest:
   identify=



MMSpdu:
 confirmed-RequestPDU=Confirmed_RequestPDU:
  invokeID=0
  listOfModifier=SequenceOf:

  confirmedServiceRequest=ConfirmedServiceRequest:
   identify=

Definition files used:
https://pastebin.com/JitDfL2R
(named it mms_classes.py)

omitEmptyOptionals = options.get(

#162

The commit message says

- Removed default initializer from `SequenceOf`/`SetOf` types to ensure
  consistent behaviour with the rest of ASN.1 types. Before this change,
  `SequenceOf`/`SetOf` instances immediately become value objects
  behaving like an empty list. With this change, `SequenceOf`/`SetOf`
  objects remain schema objects unless a component is added or
  `.clear()` is called.

In my case, it seems that I still have objects behaving as lists even when empty.

It possible to troubleshoot this issue by enabling debugging in your code:

from pyasn1 import debug
debug.setLogger(debug.Debug('encoder'))