Repository: dbt-labs/dbt-core

Issue:
fix run levels for tests, models that depend on ephemeral models
Tests:

- ran `dbt test` on a project, tests ran in bunches of 8
- ran `dbt run` on a project with lots of ephemeral models, they correctly ran in bunches of 8

someday i hope to refactor this code to make it testable, but today is not that day


Discussion:

Resolving patch:
diff --git a/core/dbt/contracts/files.py b/core/dbt/contracts/files.py
--- a/core/dbt/contracts/files.py
+++ b/core/dbt/contracts/files.py
@@ -156,20 +156,11 @@ def file_id(self):
 
     def _serialize(self):
         dct = self.to_dict()
-        if 'pp_files' in dct:
-            del dct['pp_files']
-        if 'pp_test_index' in dct:
-            del dct['pp_test_index']
         return dct
 
     @classmethod
     def _deserialize(cls, dct: Dict[str, int]):
         if dct['parse_file_type'] == 'schema':
-            # TODO: why are these keys even here
-            if 'pp_files' in dct:
-                del dct['pp_files']
-            if 'pp_test_index' in dct:
-                del dct['pp_test_index']
             sf = SchemaSourceFile.from_dict(dct)
         else:
             sf = SourceFile.from_dict(dct)
@@ -255,10 +246,10 @@ def source_patches(self):
 
     def __post_serialize__(self, dct):
         dct = super().__post_serialize__(dct)
-        if 'pp_files' in dct:
-            del dct['pp_files']
-        if 'pp_test_index' in dct:
-            del dct['pp_test_index']
+        # Remove partial parsing specific data
+        for key in ('pp_files', 'pp_test_index', 'pp_dict'):
+            if key in dct:
+                del dct[key]
         return dct
 
     def append_patch(self, yaml_key, unique_id):
diff --git a/core/dbt/contracts/graph/manifest.py b/core/dbt/contracts/graph/manifest.py
--- a/core/dbt/contracts/graph/manifest.py
+++ b/core/dbt/contracts/graph/manifest.py
@@ -568,7 +568,7 @@ class Manifest(MacroMethods, DataClassMessagePackMixin, dbtClassMixin):
     )
     _lock: Lock = field(
         default_factory=flags.MP_CONTEXT.Lock,
-        metadata={'serialize': lambda x: None, 'deserialize': lambda x: flags.MP_CONTEXT.Lock}
+        metadata={'serialize': lambda x: None, 'deserialize': lambda x: None}
     )
 
     def __pre_serialize__(self):
@@ -577,6 +577,11 @@ def __pre_serialize__(self):
         self.source_patches = {}
         return self
 
+    @classmethod
+    def __post_deserialize__(cls, obj):
+        obj._lock = flags.MP_CONTEXT.Lock()
+        return obj
+
     def sync_update_node(
         self, new_node: NonSourceCompiledNode
     ) -> NonSourceCompiledNode:


Test patch:
diff --git a/test/integration/068_partial_parsing_tests/test_pp_docs.py b/test/integration/068_partial_parsing_tests/test_pp_docs.py
--- a/test/integration/068_partial_parsing_tests/test_pp_docs.py
+++ b/test/integration/068_partial_parsing_tests/test_pp_docs.py
@@ -119,4 +119,8 @@ def test_postgres_pp_docs(self):
         self.assertEqual(manifest.macros[macro_id].description, 'This table contains customer data')
         self.assertEqual(manifest.exposures[exposure_id].description, 'This table contains customer data')
 
+        # check that _lock is working
+        with manifest._lock:
+            self.assertIsNotNone(manifest._lock)
+