You can perform a query using a complex filter that asks to use “any” filters within a group of filters. Using your example:
filters = []
# Common filters that will always be applicable
filters.append(["project", "is", {'type': 'xxxxxx', 'id': 100, 'name': 'xxxxx'}])
filters.append(["entity", "name_is", "ABC"] # Same as entity.EntityType.code but more convenient and omits the need to specify the Entity type explicitly. This alone may be an answer to your question.
# Filters that are optional but results must match at least 1 of these filters
any_filter_group = {
"filter_operator": "any",
"filters": []
}
# Request the linked Entity is either a Shot or an Asset
any_filter_group["filters"].append(["entity", "type_is", "Asset"])
any_filter_group["filters"].append(["entity", "type_is", "Shot"])
filters.append(any_filter_group)
fields = ["id", "type", "content", "entity", "step"]
sg_data = shotgun.find_one("Task", filters=sg_filters, fields=fields)