diff --git a/packages/syft/src/syft/service/api/api.py b/packages/syft/src/syft/service/api/api.py index 0c18d8a2356..2c44b6dd739 100644 --- a/packages/syft/src/syft/service/api/api.py +++ b/packages/syft/src/syft/service/api/api.py @@ -28,6 +28,16 @@ class CustomAPIEndpoint(SyftObject): __attr_searchable__ = ["path"] __attr_unique__ = ["path"] + def __eq__(self, other: Any) -> bool: + if isinstance(other, CustomAPIEndpoint): + return ( + self.path == other.path + and self.api_code == other.api_code + and self.signature == other.signature + and self.func_name == other.func_name + ) + return self == other + def exec(self, context: AuthedServiceContext, **kwargs: Any) -> Any: try: inner_function = ast.parse(self.api_code).body[0] @@ -43,7 +53,7 @@ def exec(self, context: AuthedServiceContext, **kwargs: Any) -> Any: return context, result except Exception as e: print(f"Failed to run CustomAPIEndpoint Code. {e}") - return SyftError(e) + return SyftError(message=e) def get_signature(func: Callable) -> Signature: diff --git a/packages/syft/src/syft/service/api/api_service.py b/packages/syft/src/syft/service/api/api_service.py index 4ccfaa862cb..56041bdc6dd 100644 --- a/packages/syft/src/syft/service/api/api_service.py +++ b/packages/syft/src/syft/service/api/api_service.py @@ -53,6 +53,16 @@ def update( res = self.check_type(endpoint, CustomAPIEndpoint) if res.is_err(): return res + old_endpoint = self.get_by_path(credentials=credentials, path=endpoint.path) + if old_endpoint and old_endpoint.ok(): + old_endpoint = old_endpoint.ok() + old_endpoint = old_endpoint[0] + + if old_endpoint == endpoint: + return Ok(endpoint) + else: + super().delete_by_uid(credentials=credentials, uid=old_endpoint.id) + result = super().set( credentials=credentials, obj=res.ok(), ignore_duplicates=True )