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

Location Object can't have 0 for Longitude/Latitude #572

Open
nyc3-djigarjian opened this issue Sep 7, 2023 · 2 comments
Open

Location Object can't have 0 for Longitude/Latitude #572

nyc3-djigarjian opened this issue Sep 7, 2023 · 2 comments
Labels

Comments

@nyc3-djigarjian
Copy link

nyc3-djigarjian commented Sep 7, 2023

When attempting to create Location objects with '0' as a value for either the latitude or longitude, the library raises a DependentPropertiesError when it should not. See relevant portion of the StackTrace below:

country = stix2.Location( File "/usr/local/lib/python3.9/site-packages/stix2/base.py", line 232, in __init__ self._check_object_constraints() File "/usr/local/lib/python3.9/site-packages/stix2/v21/sdo.py", line 398, in _check_object_constraints self._check_properties_dependency(['longitude'], ['latitude']) File "/usr/local/lib/python3.9/site-packages/stix2/base.py", line 109, in _check_properties_dependency raise DependentPropertiesError(self.__class__, failed_dependency_pairs) stix2.exceptions.DependentPropertiesError: The property dependencies for Location: (longitude, latitude) are not met.

I've traced the issue to the stix2\base.py _check_properties_dependency method where the function uses the "not" operator to check if a property is a valid value. In this scenario, '0' is a valid Longitude and Latitude and an additional layer of checking needs to occur for Number values. Note: Issue arises at if not self.get(p)

    def _check_properties_dependency(self, list_of_properties, list_of_dependent_properties):
        failed_dependency_pairs = []
        for p in list_of_properties:
            for dp in list_of_dependent_properties:
                if not self.get(p) and self.get(dp):
                    failed_dependency_pairs.append((p, dp))
        if failed_dependency_pairs:
            raise DependentPropertiesError(self.__class__, failed_dependency_pairs)
@ejratl ejratl added the bug label Sep 11, 2023
@ejratl
Copy link
Contributor

ejratl commented Sep 11, 2023

Thanks for the bug report and for tracking down the exact location in the code where this occurs! TIL: 0°N 0°E is known as "Null Island".

@rpiazza
Copy link
Contributor

rpiazza commented Sep 14, 2024

_check_properties_dependency mentioned above can be found at

https://github.com/oasis-open/cti-python-stix2/blob/master/stix2/base.py#L102

I think the problem is that the get method doesn't take into consideration that a value of 0 will be interpreted as None. If the property has a value of 0, then it exists, and shouldn't cause this error.

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