rbw / aiosnow

Asynchronous ServiceNow Library
MIT License
74 stars 12 forks source link

Conditional bitwise operators not concatenating in selection string correctly #32

Closed sulbig closed 4 years ago

sulbig commented 4 years ago

I had an issue with selections with multiple conditions not working correctly and discovered the bitwise & and | operators were not being concatenated in the selection string correctly. None were being added after the first bitwise operator.

Using the following example:

selection = select(
    Incident.assignment_group.equals("1234567890") &
    Incident.opened_at.after("2020-04-01") &
    Incident.incident_state.equals("7")
).order_asc(Incident.number)

...I would get: assignment_group=1234567890^opened_at>2020-04-01incident_state=7^ORDERBYnumber

I had to change the following in condition.py to make it work correctly for me.

1) Changed the concatenated variables order so that operator_logical comes first:

@property
def __str__(self):
    return (
        (self.operator_logical or "") +
        self.operand_left +
        self.operator_conditional +
        self.operand_right
    )

2) Set the operator_logical variable here before appending it to the list:

def _set_next(self, next_cond, operator):
    next_cond.operator_logical = operator
    self.selection.append(next_cond)
    return self

...and now I get: assignment_group=1234567890^opened_at>2020-04-01^incident_state=7^ORDERBYnumber

rbw commented 4 years ago

Yep, you're right. I'll include this in the next release.

PR: https://github.com/rbw/snow/pull/38

Thanks!

rbw commented 4 years ago

Fixed in #38