Repository: getmoto/moto (python)

Issue:
Incorrect behavior of SageMaker Client Search Method
# Environment Information
- Python Version: 3.8.12
- boto3 == 1.24.4
- pytest == 8.3.2
- moto == 5.0.11

# Documentation Reference

According to the [latest moto documentation](https://docs.getmoto.org/en/latest/docs/services/sagemaker.html) for sagemaker implemented services, the following methods are implemented:
- [X] create_model_package_group
- [X] list_model_package_groups
- [X] search

# Problem Description

I am currently using moto test the retrieval of model package groups based on certain tags. I created some model groups for testing, but when calling the method `sagemaker_client.search` no model package groups were returned, even when using only the `Resource` keyword. To ensure this was a problem of the search method I also used the list_model_groups method and I was able to visualize all the model package groups as expected.

# Minimal Example

**search_model_group.py**
```python 
import boto3

class ModelGroupFinder:
    def __init__(self):
        self.sm_client = boto3.client('sagemaker')
    
    def get_model_groups_with_search_method(self):
        search_results = self.sm_client.search(
            Resource='ModelPackageGroup',
            SearchExpression={
                'Filters': [{
                    'Name': 'Tags.RegisteredBySourceRoleArn', 
                    'Operator': 'Equals', 
                    'Value': 'arn:aws:iam::123456789012:role/DSSourceRole'}]}
        )
        return search_results

    def get_model_groups_with_list_model_groups_method(self):
        list_model_results = self.sm_client.list_model_package_groups()
        return list_model_results
```

**test_model_groups.py**
```python
import boto3
from moto import mock_aws
from .search_model_group import ModelGroupFinder
from pprint import pprint

MOCK_SOURCE_ROLE_ARN = 'arn:aws:iam::123456789012:role/DSSourceRole'


def mock_model_groups():
    sm_client = boto3.client('sagemaker')
    sm_client.create_model_package_group(
        ModelPackageGroupName='model-test_DEV',
        ModelPackageGroupDescription='Model group in DEV environment.',
        Tags=[
            {
                'Key': 'RegisteredBySourceRoleArn',
                'Value': MOCK_SOURCE_ROLE_ARN
            }
        ]
    )
    sm_client.create_model_package_group(
        ModelPackageGroupName='model-test_PROD',
        ModelPackageGroupDescription='Model group in PROD environment.',
        Tags=[
            {
                'Key': 'RegisteredBySourceRoleArn',
                'Value': MOCK_SOURCE_ROLE_ARN
            }
        ]
    )
    sm_client.create_model_package_group(
        ModelPackageGroupName='model-test2_DEV',
        ModelPackageGroupDescription='Model group in DEV environment.',
        Tags=[
            {
                'Key': 'RegisteredBySourceRoleArn',
                'Value': 'arn:aws:iam::123456789012:role/OtherSourceRole'
            }
        ]
    )

@mock_aws
def test_search_function():
    mock_model_groups()
    model_group_finder = ModelGroupFinder()
    model_groups = model_group_finder.get_model_groups_with_search_method()
    print('Sagemaker Search Function: ')
    pprint(model_groups)


@mock_aws
def test_list_function():
    mock_model_groups()
    model_group_finder = ModelGroupFinder()
    model_groups = model_group_finder.get_model_groups_with_list_model_groups_method()
    print('List Model Package Group Function')
    pprint(model_groups)
```

When running `pytest -s test_model_groups.py` the following print statements are shown in the console:

`Sagemaker Search Function:`
```json
{
  "ResponseMetadata": {
    "HTTPHeaders": {
      "date": "Fri, 26 Jul 2024 14:42:54 GMT",
      "server": "amazon.com",
      "x-amzn-requestid": "eKKGgAfq4hDFlUGdxTDhFLuOu5VPQTAnoIN1Zc7aDxL9HYOjZ1Xd"
    },
    "HTTPStatusCode": 200,
    "RequestId": "eKKGgAfq4hDFlUGdxTDhFLuOu5VPQTAnoIN1Zc7aDxL9HYOjZ1Xd",
    "RetryAttempts": 0
  },
  "Results": []
}

`List Model Package Group Function:`
```json
{
  "ModelPackageGroupSummaryList": [
    {
      "CreationTime": datetime.datetime(2024, 7, 26, 17, 42, 54, 711092, tzinfo=tzutc()),
      "ModelPackageGroupArn": "arn:aws:sagemaker:us-east-1:123456789012:model-package-group/model-test_DEV",
      "ModelPackageGroupDescription": "Model group in DEV environment.",
      "ModelPackageGroupName": "model-test_DEV",
      "ModelPackageGroupStatus": "Completed"
    },
    {
      "CreationTime": datetime.datetime(2024, 7, 26, 17, 42, 54, 712037, tzinfo=tzutc()),
      "ModelPackageGroupArn": "arn:aws:sagemaker:us-east-1:123456789012:model-package-group/model-test_PROD",
      "ModelPackageGroupDescription": "Model group in PROD environment.",
      "ModelPackageGroupName": "model-test_PROD",
      "ModelPackageGroupStatus": "Completed"
    },
    {
      "CreationTime": datetime.datetime(2024, 7, 26, 17, 42, 54, 712727, tzinfo=tzutc()),
      "ModelPackageGroupArn": "arn:aws:sagemaker:us-east-1:123456789012:model-package-group/model-test2_DEV",
      "ModelPackageGroupDescription": "Model group in DEV environment.",
      "ModelPackageGroupName": "model-test2_DEV",
      "ModelPackageGroupStatus": "Completed"
    }
  ],
  "ResponseMetadata": {
    "HTTPHeaders": {
      "date": "Fri, 26 Jul 2024 14:42:54 GMT",
      "server": "amazon.com",
      "x-amzn-requestid": "BCne5rUZeWfhWmeONuncUz1CkmhRLDUmtQUozDdWqtLBMsdDMNWj"
    },
    "HTTPStatusCode": 200,
    "RequestId": "BCne5rUZeWfhWmeONuncUz1CkmhRLDUmtQUozDdWqtLBMsdDMNWj",
    "RetryAttempts": 0
  }
}

```

As seen above the `sm_client.search` method is not working as expected. It is not returning any of the model groups previously created (even without any filter) while the `sm_client.list_model_package_groups` is returning all of them.

Pull request:
Sagemaker: search() now supports ModelPackageGroups
Fixes #7898



Patch:
diff --git a/moto/sagemaker/models.py b/moto/sagemaker/models.py
index 1090d5702..57a09c537 100644
--- a/moto/sagemaker/models.py
+++ b/moto/sagemaker/models.py
@@ -3179,6 +3179,23 @@ class SageMakerModelBackend(BaseBackend):
 
             for trial_component_summary in trial_component_summaries:
                 result["Results"].append({"TrialComponent": trial_component_summary})
+
+        if resource == "ModelPackageGroup":
+            package_groups = [
+                {
+                    "ModelPackageGroupArn": group.model_package_group_arn,
+                    "ModelPackageGroupDescription": group.model_package_group_description,
+                    "CreationTime": group.creation_time.strftime("%Y-%m-%d %H:%M:%S"),
+                    "ModelPackageGroupName": group.model_package_group_name,
+                    "ModelPackageGroupStatus": group.model_package_group_status,
+                    "Tags": group.tags,
+                }
+                for group in self.model_package_groups.values()
+                if evaluate_search_expression(group)
+            ]
+
+            for group in package_groups:
+                result["Results"].append({"ModelPackageGroup": group})
         return result
 
     def delete_experiment(self, experiment_name: str) -> None:


Test patch:
diff --git a/tests/test_sagemaker/test_sagemaker_model_package_groups.py b/tests/test_sagemaker/test_sagemaker_model_package_groups.py
index 9ed8c30a6..927a9491b 100644
--- a/tests/test_sagemaker/test_sagemaker_model_package_groups.py
+++ b/tests/test_sagemaker/test_sagemaker_model_package_groups.py
@@ -267,3 +267,35 @@ def test_delete_tags_model_package_group():
     for response in response_iterator:
         remaining_tags.extend(response["Tags"])
     assert remaining_tags == tags[20:]
+
+
+@mock_aws
+def test_search_model_package_groups():
+    client = boto3.client("sagemaker", region_name="eu-west-1")
+    group1 = "test-model-package-group-1"
+    desc1 = "test-model-package-group-description-1"
+    arn1 = client.create_model_package_group(
+        ModelPackageGroupName=group1, ModelPackageGroupDescription=desc1
+    )["ModelPackageGroupArn"]
+    client.add_tags(ResourceArn=arn1, Tags=[{"Key": "k1", "Value": "v1"}])
+
+    group2 = "test-model-package-group-2"
+    desc2 = "test-model-package-group-description-2"
+    client.create_model_package_group(
+        ModelPackageGroupName=group2,
+        ModelPackageGroupDescription=desc2,
+    )
+
+    summary = client.search(Resource="ModelPackageGroup")["Results"]
+    assert len(summary) == 2
+
+    assert (
+        summary[0]["ModelPackageGroup"]["ModelPackageGroupName"]
+        == "test-model-package-group-1"
+    )
+    assert summary[0]["ModelPackageGroup"]["Tags"] == [{"Key": "k1", "Value": "v1"}]
+
+    assert (
+        summary[1]["ModelPackageGroup"]["ModelPackageGroupName"]
+        == "test-model-package-group-2"
+    )