Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unwanted optional property is added while encoding. #186

Open
daniel-leicht opened this issue Nov 27, 2019 · 1 comment
Open

Unwanted optional property is added while encoding. #186

daniel-leicht opened this issue Nov 27, 2019 · 1 comment

Comments

@daniel-leicht
Copy link

daniel-leicht commented Nov 27, 2019

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)

@ptitdoc
Copy link

ptitdoc commented Jun 25, 2021

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'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants