| 124 | |
| 125 | |
| 126 | def diff_registry_objects( |
| 127 | current: FeastObject, new: FeastObject, object_type: FeastObjectType |
| 128 | ) -> FeastObjectDiff: |
| 129 | current_proto = current.to_proto() |
| 130 | new_proto = new.to_proto() |
| 131 | assert current_proto.DESCRIPTOR.full_name == new_proto.DESCRIPTOR.full_name |
| 132 | property_diffs = [] |
| 133 | transition: TransitionType = TransitionType.UNCHANGED |
| 134 | |
| 135 | current_spec: FeastObjectSpecProto |
| 136 | new_spec: FeastObjectSpecProto |
| 137 | if isinstance( |
| 138 | current_proto, (DataSourceProto, ValidationReferenceProto) |
| 139 | ) or isinstance(new_proto, (DataSourceProto, ValidationReferenceProto)): |
| 140 | assert type(current_proto) == type(new_proto) |
| 141 | current_spec = cast(DataSourceProto, current_proto) |
| 142 | new_spec = cast(DataSourceProto, new_proto) |
| 143 | else: |
| 144 | current_spec = current_proto.spec |
| 145 | new_spec = new_proto.spec |
| 146 | if current != new: |
| 147 | for _field in current_spec.DESCRIPTOR.fields: |
| 148 | if _field.name in FIELDS_TO_IGNORE: |
| 149 | continue |
| 150 | elif getattr(current_spec, _field.name) != getattr(new_spec, _field.name): |
| 151 | if _field.name == "feature_transformation": |
| 152 | current_spec = cast(OnDemandFeatureViewSpec, current_spec) |
| 153 | new_spec = cast(OnDemandFeatureViewSpec, new_spec) |
| 154 | # Check if the old proto is populated and use that if it is |
| 155 | feature_transformation_udf = ( |
| 156 | current_spec.feature_transformation.user_defined_function |
| 157 | ) |
| 158 | if ( |
| 159 | current_spec.HasField("user_defined_function") |
| 160 | and not feature_transformation_udf |
| 161 | ): |
| 162 | deprecated_udf = current_spec.user_defined_function |
| 163 | else: |
| 164 | deprecated_udf = None |
| 165 | current_udf = ( |
| 166 | deprecated_udf |
| 167 | if deprecated_udf is not None |
| 168 | else feature_transformation_udf |
| 169 | ) |
| 170 | new_udf = new_spec.feature_transformation.user_defined_function |
| 171 | for _udf_field in current_udf.DESCRIPTOR.fields: |
| 172 | if _udf_field.name == "body": |
| 173 | continue |
| 174 | if getattr(current_udf, _udf_field.name) != getattr( |
| 175 | new_udf, _udf_field.name |
| 176 | ): |
| 177 | transition = TransitionType.UPDATE |
| 178 | property_diffs.append( |
| 179 | PropertyDiff( |
| 180 | _field.name + "." + _udf_field.name, |
| 181 | getattr(current_udf, _udf_field.name), |
| 182 | getattr(new_udf, _udf_field.name), |
| 183 | ) |