| 201 | |
| 202 | |
| 203 | def diff_between( |
| 204 | current: InfraObjectProto, new: InfraObjectProto, infra_object_type: str |
| 205 | ) -> InfraObjectDiff: |
| 206 | assert current.DESCRIPTOR.full_name == new.DESCRIPTOR.full_name |
| 207 | property_diffs = [] |
| 208 | transition: TransitionType = TransitionType.UNCHANGED |
| 209 | if current != new: |
| 210 | for _field in current.DESCRIPTOR.fields: |
| 211 | if _field.name in FIELDS_TO_IGNORE: |
| 212 | continue |
| 213 | if getattr(current, _field.name) != getattr(new, _field.name): |
| 214 | transition = TransitionType.UPDATE |
| 215 | property_diffs.append( |
| 216 | PropertyDiff( |
| 217 | _field.name, |
| 218 | getattr(current, _field.name), |
| 219 | getattr(new, _field.name), |
| 220 | ) |
| 221 | ) |
| 222 | return InfraObjectDiff( |
| 223 | new.name, |
| 224 | infra_object_type, |
| 225 | current, |
| 226 | new, |
| 227 | property_diffs, |
| 228 | transition, |
| 229 | ) |