From e37ef04509daae2dfeaed9e25a3f250bb62091d4 Mon Sep 17 00:00:00 2001 From: softvar Date: Thu, 8 Jun 2023 17:42:24 +0530 Subject: [PATCH] fix(settings_file): logging for invalid settings file when fetched from server --- CHANGELOG.md | 6 ++++++ tests/core/test_mutually_exclusive_newimpl.py | 2 +- vwo/enums/log_message_enum.py | 4 +--- vwo/services/settings_file_manager.py | 16 +++++++++------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dffdace..fb8ff51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.46.1] - 2023-06-08 + +### Changed + +- Print `settings-file` in the error log in case of `get_and_update_settings_file` API fails to fetch correct settings + ## [1.46.0] - 2023-06-06 ### Added diff --git a/tests/core/test_mutually_exclusive_newimpl.py b/tests/core/test_mutually_exclusive_newimpl.py index 09c2aa5..3a52b9d 100644 --- a/tests/core/test_mutually_exclusive_newimpl.py +++ b/tests/core/test_mutually_exclusive_newimpl.py @@ -76,7 +76,7 @@ def test_traffic_weightage_campaigns(self): # remove priority from settings file and initialize local vwo instance (so that logic flows to traffic weightage) new_meg_settings_without_p = new_meg_settings - del new_meg_settings_without_p["groups"]["1"]["p"] + new_meg_settings_without_p["groups"]["1"].pop("p", None) vwo_instance = vwo.launch( json.dumps(new_meg_settings_without_p), log_level=TEST_LOG_LEVEL, diff --git a/vwo/enums/log_message_enum.py b/vwo/enums/log_message_enum.py index 4320c9b..d17c206 100644 --- a/vwo/enums/log_message_enum.py +++ b/vwo/enums/log_message_enum.py @@ -180,9 +180,7 @@ class ERROR_MESSAGES: CONNECTION_ERROR = "({file}): HTTP Connection - {reason}. Error - {err}" BATCH_EVENT_LIMIT_EXCEEDED = "({file}): Impression event - {end_point} failed due to exceeding payload size. Parameter events_per_request in batch_events config in launch API has value:{events_per_request} for accountId:{account_id}. Please read the official documentation for knowing the size limits." - INVALID_SETTINGS_FILE = ( - "({file}): [API_NAME] settings_file fetched is not proper for the account_id: {account_id}." - ) + INVALID_SETTINGS_FILE = "({file}): [API_NAME] settings_file fetched is not proper for the account_id: {account_id}, settings_file: {settings_file}" EVENT_BATCHING_NOT_OBJECT = "({file}): Batch event settings are not of type object" EVENT_BATCHING_INSUFFICIENT = ( diff --git a/vwo/services/settings_file_manager.py b/vwo/services/settings_file_manager.py index 1494c86..c473000 100644 --- a/vwo/services/settings_file_manager.py +++ b/vwo/services/settings_file_manager.py @@ -25,10 +25,10 @@ class SettingsFileManager(object): - """ VWO settings_file manager """ + """VWO settings_file manager""" def __init__(self, settings_file): - """ Init method to load and set vwo object with settings_file data. + """Init method to load and set vwo object with settings_file data. Args: settings_file (json_string): stringified json representing the vwo settings_file. @@ -38,7 +38,7 @@ def __init__(self, settings_file): # PUBLIC METHODS def process_settings_file(self): - """ Processes the settings_file, assigns variation allocation range """ + """Processes the settings_file, assigns variation allocation range""" settings_file = self.settings_file for campaign in settings_file.get("campaigns"): @@ -46,12 +46,12 @@ def process_settings_file(self): self.logger.log(LogLevelEnum.DEBUG, LogMessageEnum.DEBUG_MESSAGES.SETTINGS_FILE_PROCESSED.format(file=FILE)) def get_settings_file(self): - """ Retrieves settings file """ + """Retrieves settings file""" return self.settings_file def get_settings_file_string(self): - """ Retrieves stringified json representing the settings_file """ + """Retrieves stringified json representing the settings_file""" return self.settings_file_string @@ -74,7 +74,9 @@ def get_and_update_settings_file(self, account_id, sdk_key, is_via_webhook): if not validate_util.is_valid_settings_file(latest_settings_file): self.logger.log( LogLevelEnum.ERROR, - LogMessageEnum.ERROR_MESSAGES.INVALID_SETTINGS_FILE.format(file=FILE, account_id=account_id), + LogMessageEnum.ERROR_MESSAGES.INVALID_SETTINGS_FILE.format( + file=FILE, account_id=account_id, settings_file=latest_settings_file + ), ) return False @@ -86,7 +88,7 @@ def get_and_update_settings_file(self, account_id, sdk_key, is_via_webhook): return True def update_settings_file(self, settings_file): - """ Update the settings_file on the instance so that latest settings could be used + """Update the settings_file on the instance so that latest settings could be used from next hit onwards Args: