def is_port_message_stale(self, payload):
- orig = self.get_port_by_id(payload['id'])
- if orig and orig.get('revision', 0) > payload.get('revision', 0):
+ orig = self.get_port_by_id(payload['id']) or {}
+ if orig.get('revision_number', 0) > payload.get('revision_number', 0):
return True
if payload['id'] in self.deleted_ports:
return True
If the line had stayed 'if orig and orig.get(... ' then it would have also returned False if there was no original port, where now it can return True. So I think you are correct and something like this works better:
if orig and orig.get('revision_number', 0) >= payload.get('revision_number', 0):
return True
We can then add tests to cover the two new cases:
1) original port not found
2) revision numbers the same
I think this was slightly broken with https:/ /review. opendev. org/#/c/ 373566/ a few years ago:
def is_port_ message_ stale(self, payload): port_by_ id(payload[ 'id']) 'revision' , 0) > payload. get('revision' , 0): port_by_ id(payload[ 'id']) or {} 'revision_ number' , 0) > payload. get('revision_ number' , 0):
- orig = self.get_
- if orig and orig.get(
+ orig = self.get_
+ if orig.get(
return True
if payload['id'] in self.deleted_ports:
return True
If the line had stayed 'if orig and orig.get(... ' then it would have also returned False if there was no original port, where now it can return True. So I think you are correct and something like this works better:
if orig and orig.get( 'revision_ number' , 0) >= payload. get('revision_ number' , 0):
return True
We can then add tests to cover the two new cases:
1) original port not found
2) revision numbers the same