Skip to content

Commit 562b98a

Browse files
authored
Fix LookerHook serialize missing 1 argument error (#34678)
* Fix LookerHook serialize missing 1 argument error * Add test for LookerHook.get_looker_sdk * Re-trigger build
1 parent 3623b77 commit 562b98a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

airflow/providers/google/cloud/hooks/looker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def get_looker_sdk(self):
194194
return methods40.Looker40SDK(
195195
auth_session.AuthSession(settings, transport, serialize.deserialize40, "4.0"),
196196
serialize.deserialize40,
197-
serialize.serialize,
197+
serialize.serialize40,
198198
transport,
199199
"4.0",
200200
)

tests/providers/google/cloud/hooks/test_looker.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# under the License.
1818
from __future__ import annotations
1919

20+
from contextlib import nullcontext as does_not_raise
2021
from unittest import mock
2122

2223
import pytest
@@ -42,6 +43,30 @@ def setup_method(self):
4243
conn.return_value.extra_dejson = CONN_EXTRA
4344
self.hook = LookerHook(looker_conn_id="test")
4445

46+
@mock.patch("airflow.providers.google.cloud.hooks.looker.requests_transport")
47+
def test_get_looker_sdk(self, _):
48+
"""
49+
Test that get_looker_sdk is setting up the sdk properly
50+
51+
Note: `requests_transport` is mocked so we don't have to test
52+
looker_sdk's functionality, just LookerHook's usage of it
53+
"""
54+
self.hook.get_connection = mock.MagicMock()
55+
sdk = self.hook.get_looker_sdk()
56+
57+
# Attempting to use the instantiated SDK should not throw an error
58+
with does_not_raise():
59+
sdk.get(path="/", structure=None)
60+
sdk.delete(path="/", structure=None)
61+
62+
# The post/patch/put methods call a method internally to serialize
63+
# the body if LookerHook sets the wrong serialize function on init
64+
# there will be TypeErrors thrown
65+
# The body we pass here must be a list, dict, or model.Model
66+
sdk.post(path="/", structure=None, body=[])
67+
sdk.patch(path="/", structure=None, body=[])
68+
sdk.put(path="/", structure=None, body=[])
69+
4570
@mock.patch(HOOK_PATH.format("pdt_build_status"))
4671
def test_wait_for_job(self, mock_pdt_build_status):
4772
# replace pdt_build_status invocation with mock status

0 commit comments

Comments
 (0)