Repository: dbt-labs/dbt-core
Pull request: fix deprecation firing for microbatch model w custom strategy
Resolves #10994

### Problem

The deprecation about custom microbatch macros was being fired in the wrong instances. It was being fired a custom marcro _wasn't_ present instead of when it _was_ 🫠 

### Solution

Negate the conditional check of `self.manifest._microbatch_macro_is_core`

### Checklist

- [X] I have read [the contributing guide](https://github.com/dbt-labs/dbt-core/blob/main/CONTRIBUTING.md) and understand what's expected of me.
- [X] I have run this code in development, and it appears to resolve the stated issue.
- [X] This PR includes tests, or tests are not required or relevant for this PR.
- [X] This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
- [X] This PR includes [type annotations](https://docs.python.org/3/library/typing.html) for new and modified functions.


Problem statement:
[Bug] Deprecation warning for custom `microbatch` macros is being fired incorrectly
### 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

A deprecation warning about custom microbatch marcos is issued IFF all the following are true
1. a project _DOESNT_ have a custom "microbatch" macro
2. the `require_batched_execution_for_custom_microbatch_strategy` is set to False
3. the project has a "microbatch" model

### Expected Behavior

A deperecation warning about custom microbatch macros should only be issued IFF all the following are true
1. a project _DOES_ have a custom "microbatch" macro
2. the `require_batched_execution_for_custom_microbatch_strategy` is set to False
3. the project has a "microbatch" model

### Steps To Reproduce

1. get dbt-postgres 1.9.0b1
2. create a microbatch model in your project (without a custom "microbatch" macro)
3. run `dbt run`
4. observe the deprecation warning

### Relevant log output

_No response_

### Environment

```markdown
- OS:
- Python:
- dbt:
```


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

_No response_

### Additional Context

_No response_

Hints from issue discussion:

Commit message: Add changie doc

Patch to review:
diff --git a/.changes/unreleased/Fixes-20241112-210839.yaml b/.changes/unreleased/Fixes-20241112-210839.yaml
new file mode 100644
index 00000000000..031e160f092
--- /dev/null
+++ b/.changes/unreleased/Fixes-20241112-210839.yaml
@@ -0,0 +1,6 @@
+kind: Fixes
+body: Correct when custom microbatch macro deprecation warning is fired
+time: 2024-11-12T21:08:39.866837-06:00
+custom:
+  Author: QMalcolm MichelleArk
+  Issue: "10994"
diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py
index 6743bf5e6e7..fbfc83cd6c5 100644
--- a/core/dbt/parser/manifest.py
+++ b/core/dbt/parser/manifest.py
@@ -662,7 +662,7 @@ def check_for_microbatch_deprecations(self) -> None:
                     has_microbatch_model = True
                     break
 
-            if has_microbatch_model and self.manifest._microbatch_macro_is_core(
+            if has_microbatch_model and not self.manifest._microbatch_macro_is_core(
                 self.root_project.project_name
             ):
                 dbt.deprecations.warn("microbatch-macro-outside-of-batches-deprecation")
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 20605e632b8..4f0a8f68fa8 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -1,4 +1,4 @@
-git+https://github.com/dbt-labs/dbt-adapters.git@main
+git+https://github.com/dbt-labs/dbt-adapters.git@fix-microbatch-behavior-flag-conditional
 git+https://github.com/dbt-labs/dbt-adapters.git@main#subdirectory=dbt-tests-adapter
 git+https://github.com/dbt-labs/dbt-common.git@main
 git+https://github.com/dbt-labs/dbt-postgres.git@main
diff --git a/tests/functional/microbatch/test_microbatch.py b/tests/functional/microbatch/test_microbatch.py
index b98ad38caa9..3de48225f44 100644
--- a/tests/functional/microbatch/test_microbatch.py
+++ b/tests/functional/microbatch/test_microbatch.py
@@ -182,19 +182,16 @@ def test_use_custom_microbatch_strategy_by_default(
         project,
         deprecation_catcher: EventCatcher,
     ):
-        with mock.patch.object(
-            type(project.adapter), "valid_incremental_strategies", lambda _: []
-        ):
-            # Initial run
-            run_dbt(["run"])
+        # Initial run fires deprecation
+        run_dbt(["run"], callbacks=[deprecation_catcher.catch])
+        # Deprecation warning about custom microbatch macro fired
+        assert len(deprecation_catcher.caught_events) == 1
 
-            # Incremental run uses custom strategy
-            _, logs = run_dbt_and_capture(["run"])
-            assert "custom microbatch strategy" in logs
-            # The custom strategy wasn't used with batch functionality
-            assert "START batch" not in logs
-            # Deprecation warning about custom microbatch macro fired
-            assert len(deprecation_catcher.caught_events) == 0
+        # Incremental run uses custom strategy
+        _, logs = run_dbt_and_capture(["run"])
+        assert "custom microbatch strategy" in logs
+        # The custom strategy wasn't used with batch functionality
+        assert "START batch" not in logs
 
 
 class TestMicrobatchCustomUserStrategyProjectFlagTrueValid(BaseMicrobatchCustomUserStrategy):
@@ -208,7 +205,9 @@ def test_use_custom_microbatch_strategy_project_flag_true_invalid_incremental_st
         ):
             # Initial run
             with patch_microbatch_end_time("2020-01-03 13:57:00"):
-                run_dbt(["run"])
+                run_dbt(["run"], callbacks=[deprecation_catcher.catch])
+            # Deprecation warning about custom microbatch macro not fired
+            assert len(deprecation_catcher.caught_events) == 0
 
             # Incremental run uses custom strategy
             with patch_microbatch_end_time("2020-01-03 13:57:00"):
@@ -216,11 +215,11 @@ def test_use_custom_microbatch_strategy_project_flag_true_invalid_incremental_st
             assert "custom microbatch strategy" in logs
             # The custom strategy was used with batch functionality
             assert "START batch" in logs
-            # Deprecation warning about custom microbatch macro not fired
-            assert len(deprecation_catcher.caught_events) == 0
 
 
-class TestMicrobatchCustomUserStrategyProjectFlagTrueInvalid(BaseMicrobatchCustomUserStrategy):
+class TestMicrobatchCustomUserStrategyProjectFlagTrueNoValidBuiltin(
+    BaseMicrobatchCustomUserStrategy
+):
     def test_use_custom_microbatch_strategy_project_flag_true_invalid_incremental_strategy(
         self, project
     ):
@@ -228,10 +227,15 @@ def test_use_custom_microbatch_strategy_project_flag_true_invalid_incremental_st
             type(project.adapter), "valid_incremental_strategies", lambda _: []
         ):
             # Run of microbatch model while adapter doesn't have a "valid"
-            # microbatch strategy causes an error to be raised
+            # microbatch strategy causes no error when behaviour flag set to true
+            # and there is a custom microbatch macro
             with patch_microbatch_end_time("2020-01-03 13:57:00"):
-                _, logs = run_dbt_and_capture(["run"], expect_pass=False)
-            assert "'microbatch' is not valid" in logs
+                _, logs = run_dbt_and_capture(["run"])
+            assert "'microbatch' is not valid" not in logs
+            assert (
+                "The use of a custom microbatch macro outside of batched execution is deprecated"
+                not in logs
+            )
 
 
 class BaseMicrobatchTest:


Code review comments:
diff_hunk: @@ -1,4 +1,4 @@
-git+https://github.com/dbt-labs/dbt-adapters.git@main
+git+https://github.com/dbt-labs/dbt-adapters.git@fix-microbatch-behavior-flag-conditional
path: dev-requirements.txt
text: @user1:
We have to undo this change before merging