Repository: dbt-labs/dbt-core

Issue:
[CT-1461] [Bug] DepsNotifyUpdatesAvailable is not serializable
### Is this a new bug in dbt-core?

- [X] I believe this is a new bug in dbt-core
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

`dbt --log-format json deps` logs the following error event when installing a package that has an update available:

> {"exc": "type DepsNotifyUpdatesAvailable is not serializable. 'str' object has no attribute 'to_dict'", "info": {"code": "Z002", "extra": {}, "invocation_id": "1e59a3df-3a23-42d9-aa45-d2246092cd70", "level": "error", "msg": "Encountered an error:\ntype DepsNotifyUpdatesAvailable is not serializable. 'str' object has no attribute 'to_dict'", "name": "MainEncounteredError", "pid": 51212, "thread": "MainThread", "ts": "2022-11-02T00:02:17.987107Z"}}

`dbt --log-format text deps` runs as expected without issue: 

```bash
❯ dbt --log-format text deps
00:05:25  Running with dbt=1.4.0-a1
00:05:25  Installing dbt-labs/snowplow
00:05:26    Installed from version 0.7.0
00:05:26    Updated version available: 0.14.0
00:05:26  
00:05:26  Updates available for packages: ['dbt-labs/snowplow']                 
Update your versions in packages.yml, then run dbt deps
```



### Expected Behavior

```bash
❯ dbt --log-format json deps
{"info": {"code": "A001", "extra": {}, "invocation_id": "d8f6d0b4-7d7c-4f54-a1c6-263e821dff7a", "level": "info", "msg": "Running with dbt=1.4.0-a1", "name": "MainReportVersion", "pid": 55065, "thread": "MainThread", "ts": "2022-11-02T00:11:35.695241Z"}, "log_version": 3, "version": "=1.4.0-a1"}
{"info": {"code": "M014", "extra": {}, "invocation_id": "d8f6d0b4-7d7c-4f54-a1c6-263e821dff7a", "level": "info", "msg": "Installing dbt-labs/snowplow", "name": "DepsStartPackageInstall", "pid": 55065, "thread": "MainThread", "ts": "2022-11-02T00:11:35.833187Z"}, "package_name": "dbt-labs/snowplow"}
{"info": {"code": "M015", "extra": {}, "invocation_id": "d8f6d0b4-7d7c-4f54-a1c6-263e821dff7a", "level": "info", "msg": "  Installed from version 0.7.0", "name": "DepsInstallInfo", "pid": 55065, "thread": "MainThread", "ts": "2022-11-02T00:11:36.126860Z"}, "version_name": "version 0.7.0"}
{"info": {"code": "M016", "extra": {}, "invocation_id": "d8f6d0b4-7d7c-4f54-a1c6-263e821dff7a", "level": "info", "msg": "  Updated version available: 0.14.0", "name": "DepsUpdateAvailable", "pid": 55065, "thread": "MainThread", "ts": "2022-11-02T00:11:36.127429Z"}, "version_latest": "0.14.0"}
{"info": {"code": "M019", "extra": {}, "invocation_id": "d8f6d0b4-7d7c-4f54-a1c6-263e821dff7a", "level": "info", "msg": "Updates available for packages: ['dbt-labs/snowplow']                 \nUpdate your versions in packages.yml, then run dbt deps", "name": "DepsNotifyUpdatesAvailable", "pid": 55065, "thread": "MainThread", "ts": "2022-11-02T00:11:36.128351Z"}, "packages": {"value": ["dbt-labs/snowplow"]}}
❯ echo $?
0
```

### Steps To Reproduce

1. On latest `main` branch of `dbt-core`
2. With the following `packages.yml` added to the `jaffle_shop` project:
```yaml
packages:
  - package: dbt-labs/snowplow
    version: 0.7.0
```
3. Run `dbt --log-format json deps`


### Relevant log output

```shell
...
tput, both console and file\n  File \"/Users/michelleark/src-test/dbt-core/core/dbt/events/functions.py\", line 183, in create_json_log_line\n    raw_log_line = event_to_json(e)\n  File \"/Users/michelleark/src-test/dbt-core/core/dbt/events/functions.py\", line 124, in event_to_json\n    event_dict = event_to_dict(event)\n  File \"/Users/michelleark/src-test/dbt-core/core/dbt/events/functions.py\", line 139, in event_to_dict\n    raise Exception(f\"type {event_type} is not serializable. {str(exc)}\")\nException: type DepsNotifyUpdatesAvailable is not serializable. 'str' object has no attribute 'to_dict'\n"}
```
```


### Environment

```markdown
- OS: macOS Monterey 12.2.1
- Python: 3.10.6
- dbt: 1.4.0-a1
```


### Which database adapter are you using with dbt?

snowflake

### Additional Context

_No response_


Discussion:

Resolving patch:
diff --git a/core/dbt/deps/base.py b/core/dbt/deps/base.py
--- a/core/dbt/deps/base.py
+++ b/core/dbt/deps/base.py
@@ -74,7 +74,7 @@ def _fetch_metadata(self, project, renderer):
         raise NotImplementedError
 
     @abc.abstractmethod
-    def install(self, project):
+    def install(self, project, renderer):
         raise NotImplementedError
 
     @abc.abstractmethod
diff --git a/core/dbt/events/types.py b/core/dbt/events/types.py
--- a/core/dbt/events/types.py
+++ b/core/dbt/events/types.py
@@ -1706,7 +1706,7 @@ def code(self):
     def message(self) -> str:
         return "Updates available for packages: {} \
                 \nUpdate your versions in packages.yml, then run dbt deps".format(
-            self.packages
+            self.packages.value
         )
 
 
diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py
--- a/core/dbt/task/deps.py
+++ b/core/dbt/task/deps.py
@@ -1,3 +1,5 @@
+from typing import Optional
+
 import dbt.utils
 import dbt.deprecations
 import dbt.exceptions
@@ -6,7 +8,9 @@
 from dbt.config.renderer import DbtProjectYamlRenderer
 from dbt.deps.base import downloads_directory
 from dbt.deps.resolver import resolve_packages
+from dbt.deps.registry import RegistryPinnedPackage
 
+from dbt.events.proto_types import ListOfStrings
 from dbt.events.functions import fire_event
 from dbt.events.types import (
     DepsNoPackagesFound,
@@ -29,7 +33,9 @@ class DepsTask(BaseTask):
     def __init__(self, args, config: UnsetProfileConfig):
         super().__init__(args=args, config=config)
 
-    def track_package_install(self, package_name: str, source_type: str, version: str) -> None:
+    def track_package_install(
+        self, package_name: str, source_type: str, version: Optional[str]
+    ) -> None:
         # Hub packages do not need to be hashed, as they are public
         # Use the string 'local' for local package versions
         if source_type == "local":
@@ -45,7 +51,7 @@ def track_package_install(self, package_name: str, source_type: str, version: st
             {"name": package_name, "source": source_type, "version": version},
         )
 
-    def run(self):
+    def run(self) -> None:
         system.make_directory(self.config.packages_install_path)
         packages = self.config.packages.packages
         if not packages:
@@ -66,7 +72,7 @@ def run(self):
                 fire_event(DepsStartPackageInstall(package_name=package_name))
                 package.install(self.config, renderer)
                 fire_event(DepsInstallInfo(version_name=package.nice_version_name()))
-                if source_type == "hub":
+                if isinstance(package, RegistryPinnedPackage):
                     version_latest = package.get_version_latest()
                     if version_latest != version:
                         packages_to_upgrade.append(package_name)
@@ -81,7 +87,7 @@ def run(self):
                 )
             if packages_to_upgrade:
                 fire_event(EmptyLine())
-                fire_event(DepsNotifyUpdatesAvailable(packages=packages_to_upgrade))
+                fire_event(DepsNotifyUpdatesAvailable(packages=ListOfStrings(packages_to_upgrade)))
 
     @classmethod
     def from_args(cls, args):


Test patch:
diff --git a/tests/unit/test_events.py b/tests/unit/test_events.py
--- a/tests/unit/test_events.py
+++ b/tests/unit/test_events.py
@@ -13,7 +13,7 @@
     ErrorLevel,
     TestLevel,
 )
-from dbt.events.proto_types import NodeInfo, RunResultMsg, ReferenceKeyMsg
+from dbt.events.proto_types import ListOfStrings, NodeInfo, RunResultMsg, ReferenceKeyMsg
 from importlib import reload
 import dbt.events.functions as event_funcs
 import dbt.flags as flags
@@ -321,7 +321,8 @@ def MockNode():
     DepsInstallInfo(version_name=""),
     DepsUpdateAvailable(version_latest=""),
     DepsListSubdirectory(subdirectory=""),
-    DepsNotifyUpdatesAvailable(packages=[]),
+    DepsNotifyUpdatesAvailable(packages=ListOfStrings()),
+    DepsNotifyUpdatesAvailable(packages=ListOfStrings(['dbt-utils'])),
     DatabaseErrorRunningHook(hook_type=""),
     EmptyLine(),
     HooksRunning(num_hooks=0, hook_type=""),