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

Creating LanguageContent object has error #238

Closed
jmgnc opened this issue Jan 5, 2019 · 3 comments
Closed

Creating LanguageContent object has error #238

jmgnc opened this issue Jan 5, 2019 · 3 comments
Assignees
Labels
Milestone

Comments

@jmgnc
Copy link
Contributor

jmgnc commented Jan 5, 2019

If you pass a language content object an empty contents dictionary, you get an exception saying it must be non-empty. I do not see anywhere in the 2.1 specification that requires this.

from stix2.v21 import LanguageContent, Campaign
camp = Campaign(name='foo')
LanguageContent(object_ref=camp.id, object_modified=camp.modified, contents={})

produces:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jmg/work/cti-i18n/p/lib/python2.7/site-packages/stix2/base.py", line 161, in __init__
    self._check_property(prop_name, prop_metadata, setting_kwargs)
  File "/Users/jmg/work/cti-i18n/p/lib/python2.7/site-packages/stix2/base.py", line 94, in _check_property
    raise InvalidValueError(self.__class__, prop_name, reason=str(exc))
stix2.exceptions.InvalidValueError: Invalid value for LanguageContent 'contents': The dictionary property must contain a non-empty dictionary
@jmgnc
Copy link
Contributor Author

jmgnc commented Jan 5, 2019

also, surprisingly, if you provide one "language" w/ no translations, it works fine:

>>> LanguageContent(object_ref=camp.id, object_modified=camp.modified, contents={ 'bogus': {}})
LanguageContent(type='language-content', spec_version='2.1', id='language-content--87a5dfb2-c720-4e93-bc08-98666be73774', created='2019-01-05T00:04:16.827Z', modified='2019-01-05T00:04:16.827Z', object_ref='campaign--ed4dc7dc-f168-45e8-a72b-3a11eb5c156d', object_modified='2019-01-04T23:59:16.778Z', contents={'bogus': {}})                                                                                          

@clenk
Copy link
Contributor

clenk commented Jan 7, 2019

@jmgnc Yes, you're correct. The observed-data.objects property has a non-empty requirement and I had copied some code for dictionary properties in general. We'll get this fixed; thanks for filing an issue!

@jmgnc
Copy link
Contributor Author

jmgnc commented Jan 14, 2019

Thanks for the quick resolution! Now I can remove some work around code.

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

No branches or pull requests

3 participants