Skip to content

Commit

Permalink
add try and exception for None raw_body issue in config, and bump up …
Browse files Browse the repository at this point in the history
…version (#71)
  • Loading branch information
HzANut authored Sep 21, 2022
1 parent 3a6a63b commit 66dcc35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions moesifdjango/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,23 @@ def get_sampling_percentage(cls, config, user_id, company_id):
"""Get sampling percentage"""

if config is not None:
config_body = json.loads(config.raw_body)
try:
config_body = json.loads(config.raw_body)

user_sample_rate = config_body.get('user_sample_rate', None)
user_sample_rate = config_body.get('user_sample_rate', None)

company_sample_rate = config_body.get('company_sample_rate', None)
company_sample_rate = config_body.get('company_sample_rate', None)

if user_id and user_sample_rate and user_id in user_sample_rate:
return user_sample_rate[user_id]
if user_id and user_sample_rate and user_id in user_sample_rate:
return user_sample_rate[user_id]

if company_id and company_sample_rate and company_id in company_sample_rate:
return company_sample_rate[company_id]
if company_id and company_sample_rate and company_id in company_sample_rate:
return company_sample_rate[company_id]

return config_body.get('sample_rate', 100)
else:
return 100
return config_body.get('sample_rate', 100)
except Exception as e:
print("Error while parsing user or company sample rate")
print(e)

# Use default
return 100
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='2.1.5',
version='2.1.6',

description='Moesif Middleware for Python Django',
long_description=long_description,
Expand Down

0 comments on commit 66dcc35

Please sign in to comment.