diff --git a/ayon_api/_api.py b/ayon_api/_api.py index b1af5f6cd..d18a1b67e 100644 --- a/ayon_api/_api.py +++ b/ayon_api/_api.py @@ -871,16 +871,17 @@ def get_event( def get_events( - topics=None, - event_ids=None, - project_names=None, - states=None, - users=None, - include_logs=None, - has_children=None, - newer_than=None, - older_than=None, - fields=None, + topics: Optional[Iterable[str]] = None, + event_ids: Optional[Iterable[str]] = None, + project_names: Optional[Iterable[str]] = None, + statuses: Optional[Iterable[str]] = None, + users: Optional[Iterable[str]] = None, + include_logs: Optional[bool] = None, + has_children: Optional[bool] = None, + newer_than: Optional[str] = None, + older_than: Optional[str] = None, + fields: Optional[Iterable[str]] = None, + states: Optional[Iterable[str]] = None, ): """Get events from server with filtering options. @@ -892,7 +893,7 @@ def get_events( event_ids (Optional[Iterable[str]]): Event ids. project_names (Optional[Iterable[str]]): Project on which event happened. - states (Optional[Iterable[str]]): Filtering by states. + statuses (Optional[Iterable[str]]): Filtering by statuses. users (Optional[Iterable[str]]): Filtering by users who created/triggered an event. include_logs (Optional[bool]): Query also log events. @@ -904,6 +905,8 @@ def get_events( iso datetime string. fields (Optional[Iterable[str]]): Fields that should be received for each event. + states (Optional[Iterable[str]]): DEPRECATED Filtering by states. + Use 'statuses' instead. Returns: Generator[dict[str, Any]]: Available events matching filters. @@ -914,13 +917,14 @@ def get_events( topics=topics, event_ids=event_ids, project_names=project_names, - states=states, + statuses=statuses, users=users, include_logs=include_logs, has_children=has_children, newer_than=newer_than, older_than=older_than, fields=fields, + states=states, ) diff --git a/ayon_api/graphql_queries.py b/ayon_api/graphql_queries.py index 999c9e5c2..49acc299e 100644 --- a/ayon_api/graphql_queries.py +++ b/ayon_api/graphql_queries.py @@ -570,23 +570,26 @@ def workfiles_info_graphql_query(fields): return query -def events_graphql_query(fields): +def events_graphql_query(fields, use_states=False): query = GraphQlQuery("Events") topics_var = query.add_variable("eventTopics", "[String!]") ids_var = query.add_variable("eventIds", "[String!]") projects_var = query.add_variable("projectNames", "[String!]") - states_var = query.add_variable("eventStates", "[String!]") + statuses_var = query.add_variable("eventStatuses", "[String!]") users_var = query.add_variable("eventUsers", "[String!]") include_logs_var = query.add_variable("includeLogsFilter", "Boolean!") has_children_var = query.add_variable("hasChildrenFilter", "Boolean!") newer_than_var = query.add_variable("newerThanFilter", "String!") older_than_var = query.add_variable("olderThanFilter", "String!") + statuses_filter_name = "statuses" + if use_states: + statuses_filter_name = "states" events_field = query.add_field_with_edges("events") events_field.set_filter("ids", ids_var) events_field.set_filter("topics", topics_var) events_field.set_filter("projects", projects_var) - events_field.set_filter("states", states_var) + events_field.set_filter(statuses_filter_name, statuses_var) events_field.set_filter("users", users_var) events_field.set_filter("includeLogs", include_logs_var) events_field.set_filter("hasChildren", has_children_var) diff --git a/ayon_api/server_api.py b/ayon_api/server_api.py index 19ddf8a0c..184560a5d 100644 --- a/ayon_api/server_api.py +++ b/ayon_api/server_api.py @@ -1455,16 +1455,17 @@ def get_event(self, event_id): def get_events( self, - topics=None, - event_ids=None, - project_names=None, - states=None, - users=None, - include_logs=None, - has_children=None, - newer_than=None, - older_than=None, - fields=None + topics: Optional[Iterable[str]] = None, + event_ids: Optional[Iterable[str]] = None, + project_names: Optional[Iterable[str]] = None, + statuses: Optional[Iterable[str]] = None, + users: Optional[Iterable[str]] = None, + include_logs: Optional[bool] = None, + has_children: Optional[bool] = None, + newer_than: Optional[str] = None, + older_than: Optional[str] = None, + fields: Optional[Iterable[str]] = None, + states: Optional[Iterable[str]] = None, ): """Get events from server with filtering options. @@ -1476,7 +1477,7 @@ def get_events( event_ids (Optional[Iterable[str]]): Event ids. project_names (Optional[Iterable[str]]): Project on which event happened. - states (Optional[Iterable[str]]): Filtering by states. + statuses (Optional[Iterable[str]]): Filtering by statuses. users (Optional[Iterable[str]]): Filtering by users who created/triggered an event. include_logs (Optional[bool]): Query also log events. @@ -1488,18 +1489,31 @@ def get_events( iso datetime string. fields (Optional[Iterable[str]]): Fields that should be received for each event. + states (Optional[Iterable[str]]): DEPRECATED Filtering by states. + Use 'statuses' instead. Returns: Generator[dict[str, Any]]: Available events matching filters. """ + if statuses is None and states is not None: + warnings.warn( + ( + "Used deprecated argument 'states' in 'get_events'." + " Use 'statuses' instead." + ), + DeprecationWarning + ) + statuses = states + + filters = {} if not _prepare_list_filters( filters, ("eventTopics", topics), ("eventIds", event_ids), ("projectNames", project_names), - ("eventStates", states), + ("eventStatuses", statuses), ("eventUsers", users), ): return @@ -1519,7 +1533,10 @@ def get_events( if not fields: fields = self.get_default_fields_for_type("event") - query = events_graphql_query(set(fields)) + major, minor, patch, _, _ = self.server_version_tuple + use_states = (major, minor, patch) <= (1, 5, 6) + + query = events_graphql_query(set(fields), use_states) for attr, filter_value in filters.items(): query.set_variable_value(attr, filter_value)