Skip to content

Commit

Permalink
fix: Invalid key error for metric_filter and dimension_filter (#187)
Browse files Browse the repository at this point in the history
This PR fixes the issue introduced by #186.

It was causing the tap to break if no metric filter or dimensions are
defined in the reports.json, or if these keys are defined with
_camelCase_ notation, which would be reasonable given it's a JSON file
and all the other dimension and metric values use _camelCase_ notation.

The issue was that the keys were defined with _camelCase_ on lines
113-114 on the `client.py` file when initializing the
`report_definition` dictionary, but it then tries to access them using
_snake_case_ notation on lines 267-268, which caused the tap to break
with an invalid key error.
  • Loading branch information
pedroceriotti authored May 5, 2024
1 parent 53cd5a0 commit 8709810
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tap_google_analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ def _generate_report_definition(report_def_raw):
for metric in report_def_raw["metrics"]:
report_definition["metrics"].append(Metric(name=metric))

if "metric_filter" in report_def_raw:
report_definition["metric_filter"] = report_def_raw["metric_filter"]
if "metricFilter" in report_def_raw:
report_definition["metricFilter"] = report_def_raw["metricFilter"]

if "dimension_filter" in report_def_raw:
report_definition["dimension_filter"] = report_def_raw["dimension_filter"]
if "dimensionFilter" in report_def_raw:
report_definition["dimensionFilter"] = report_def_raw["dimensionFilter"]

# Add segmentIds to the request if the stream contains them
if "segments" in report_def_raw:
Expand Down Expand Up @@ -264,8 +264,8 @@ def _query_api(self, report_definition, state_filter, pageToken=None) -> RunRepo
metrics=report_definition["metrics"],
date_ranges=[DateRange(start_date=state_filter, end_date=self.end_date)],
limit=self.page_size,
metric_filter=report_definition["metric_filter"],
dimension_filter=report_definition["dimension_filter"],
metric_filter=report_definition["metricFilter"],
dimension_filter=report_definition["dimensionFilter"],
offset=(pageToken or 0) * self.page_size,
)

Expand Down

0 comments on commit 8709810

Please sign in to comment.