Skip to content

anded expressions evaluate different objects unless parenthesized #665

@Saviq

Description

@Saviq

Bug Description

According to the documentation:

It’s not possible to refer to two different resources, from the same resource group, in one resource expression.

Consider this test:

    def test_evaluate_same_object(self):
        resource_map = {
            'a': [Resource({'foo': 1, 'baz': 'b'}), Resource({'foo': 2, 'baz': 'a'})],
        }
        expr = ResourceExpression("a.foo == 1 and a.baz != 'b'")
        self.assertFalse(expr.evaluate(
            resource_map['a'],
            resource_map=resource_map
        ))

And it failing:

FAIL: test_evaluate_same_object (plainbox.impl.test_resource.ResourceExpressionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/michal/dev/canonical/checkbox/checkbox-ng/plainbox/impl/test_resource.py", line 426, in test_evaluate_same_object
    self.assertFalse(expr.evaluate(
AssertionError: True is not false

There is not a single resource whose foo is 1, and baz is not b. But the expression succeeds. Wrapping the first expression in parentheses makes it work as intended.

To Reproduce

Run the above test.

Environment

N/A

Relevant log output

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions