Repository: meltano/sdk
Pull request #2870 (2025-02-05 15:20:59)

fix(taps): Do not emit a warning needlessly when `rest_method` is not set in a stream class
## Related

- https://github.com/meltano/sdk/issues/2869

## Summary by Sourcery

Bug Fixes:
- Resolve an issue where a warning was unnecessarily emitted when `rest_method` was not set in a stream class.

<!-- readthedocs-preview meltano-sdk start -->
----
📚 Documentation preview 📚: https://meltano-sdk--2870.org.readthedocs.build/en/2870/

<!-- readthedocs-preview meltano-sdk end -->

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/meltano/sdk/pull/2870?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 91.33%. Comparing base [(`1d00bfc`)](https://app.codecov.io/gh/meltano/sdk/commit/1d00bfc20f7ffcb6ab87384a6cc8621783dd2b6a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano) to head [(`28e4c17`)](https://app.codecov.io/gh/meltano/sdk/commit/28e4c17edad22a4b7504350cc1895d1aaea989e3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #2870      +/-   ##
==========================================
- Coverage   91.34%   91.33%   -0.01%     
==========================================
  Files          62       62              
  Lines        5209     5203       -6     
  Branches      673      675       +2     
==========================================
- Hits         4758     4752       -6     
  Misses        319      319              
  Partials      132      132              
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/meltano/sdk/pull/2870?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=meltano).

codspeed-hq[bot]: <!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
<!-- __CODSPEED_INSTRUMENTATION_PERFORMANCE_REPORT_COMMENT__ -->

## [CodSpeed Performance Report](https://codspeed.io/meltano/sdk/branches/edgarrmondragon%2Ffix%2Fdo-not-emit-rest_method-warning-unnecessarily)

### Merging #2870 will **not alter performance**

<sub>Comparing <code>edgarrmondragon/fix/do-not-emit-rest_method-warning-unnecessarily</code> (28e4c17) with <code>main</code> (1d00bfc)</sub>



### Summary

`✅ 7` untouched benchmarks  





Patch:
diff --git a/singer_sdk/streams/graphql.py b/singer_sdk/streams/graphql.py
index 22a5fb0c..a9aa86a0 100644
--- a/singer_sdk/streams/graphql.py
+++ b/singer_sdk/streams/graphql.py
@@ -24,7 +24,7 @@ class GraphQLStream(RESTStream, t.Generic[_TToken], metaclass=abc.ABCMeta):
     """
 
     path = ""
-    rest_method = "POST"
+    http_method = "POST"
 
     @classproperty
     def records_jsonpath(cls) -> str:  # type: ignore[override] # noqa: N805
diff --git a/singer_sdk/streams/rest.py b/singer_sdk/streams/rest.py
index cb964c24..3cc29154 100644
--- a/singer_sdk/streams/rest.py
+++ b/singer_sdk/streams/rest.py
@@ -6,7 +6,6 @@ import abc
 import copy
 import decimal
 import logging
-import sys
 import typing as t
 from functools import cached_property
 from http import HTTPStatus
@@ -29,11 +28,6 @@ from singer_sdk.pagination import (
 )
 from singer_sdk.streams.core import Stream
 
-if sys.version_info < (3, 13):
-    from typing_extensions import deprecated
-else:
-    from warnings import deprecated  # pragma: no cover
-
 if t.TYPE_CHECKING:
     from collections.abc import Iterable, Mapping
     from datetime import datetime
@@ -144,39 +138,21 @@ class _HTTPStream(Stream, t.Generic[_TToken], metaclass=abc.ABCMeta):  # noqa: P
 
     # HTTP Request functions
 
-    @property
-    @deprecated(
-        "Use `http_method` instead.",
-        category=SingerSDKDeprecationWarning,
-    )
-    def rest_method(self) -> str:
-        """HTTP method to use for requests. Defaults to "GET".
-
-        .. deprecated:: 0.43.0
-           Override :meth:`~singer_sdk.RESTStream.http_method` instead.
-        """
-        return self._http_method or "GET"
-
-    @rest_method.setter
-    @deprecated(
-        "Use `http_method` instead.",
-        category=SingerSDKDeprecationWarning,
-    )
-    def rest_method(self, value: str) -> None:
-        """Set the HTTP method for requests.
-
-        Args:
-            value: The HTTP method to use for requests.
-
-        .. deprecated:: 0.43.0
-           Override :meth:`~singer_sdk.RESTStream.http_method` instead.
-        """
-        self._http_method = value
-
     @property
     def http_method(self) -> str:
         """HTTP method to use for requests. Defaults to "GET"."""
-        return self._http_method or self.rest_method
+        if self._http_method:
+            return self._http_method
+
+        if hasattr(self, "rest_method"):
+            warn(
+                "Use `http_method` instead.",
+                SingerSDKDeprecationWarning,
+                stacklevel=2,
+            )
+            return self.rest_method  # type: ignore[no-any-return]
+
+        return "GET"
 
     @http_method.setter
     def http_method(self, value: str) -> None:


Test patch:
diff --git a/tests/core/test_streams.py b/tests/core/test_streams.py
index 8e4f164c..7d1b869f 100644
--- a/tests/core/test_streams.py
+++ b/tests/core/test_streams.py
@@ -7,6 +7,7 @@ import decimal
 import logging
 import typing as t
 import urllib.parse
+import warnings
 
 import pytest
 import requests
@@ -589,6 +590,10 @@ def test_mutate_http_method(tap: Tap, requests_mock: requests_mock.Mocker):
         context.reason = "Method Not Allowed"
         return {"error": "Check your method"}
 
+    with warnings.catch_warnings():
+        warnings.simplefilter("error")
+        assert RestTestStream(tap).http_method == "GET"
+
     class PostStream(RestTestStream):
         records_jsonpath = "$.data[*]"
         path = "/endpoint"
@@ -603,10 +608,16 @@ def test_mutate_http_method(tap: Tap, requests_mock: requests_mock.Mocker):
     with pytest.raises(FatalAPIError, match="Method Not Allowed"):
         list(stream.request_records(None))
 
-    with pytest.warns(SingerSDKDeprecationWarning):
-        stream.rest_method = "GET"
+    assert hasattr(stream, "http_method")
+    assert not hasattr(stream, "rest_method")
 
-    with pytest.raises(FatalAPIError, match="Method Not Allowed"):
+    stream.http_method = None
+    stream.rest_method = "GET"
+
+    with (
+        pytest.raises(FatalAPIError, match="Method Not Allowed"),
+        pytest.warns(SingerSDKDeprecationWarning),
+    ):
         list(stream.request_records(None))
 
     stream.http_method = "POST"