diff --git a/modal/app.py b/modal/app.py index 23abc3955..cb1d31c3c 100644 --- a/modal/app.py +++ b/modal/app.py @@ -492,13 +492,19 @@ def _init_container(self, client: _Client, running_app: RunningApp): _App._container_app = running_app - # Hydrate objects on app - indexed_objects = dict(**self._functions, **self._classes) - for tag, object_id in running_app.tag_to_object_id.items(): - if tag in indexed_objects: - obj = indexed_objects[tag] - handle_metadata = running_app.object_handle_metadata[object_id] - obj._hydrate(object_id, client, handle_metadata) + # Hydrate objects on app -- hydrating functions first so that when a class is being hydrated its + # corresponding class service function is already hydrated. + def hydrate_objects(objects_dict): + for tag, object_id in running_app.tag_to_object_id.items(): + if tag in objects_dict: + obj = objects_dict[tag] + handle_metadata = running_app.object_handle_metadata[object_id] + obj._hydrate(object_id, client, handle_metadata) + + # Hydrate function objects + hydrate_objects(self._functions) + # Hydrate class objects + hydrate_objects(self._classes) @property def registered_functions(self) -> Dict[str, _Function]: