Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7e8566b4
Commit
7e8566b4
authored
Jul 14, 2017
by
Robert Raposa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix course override caching bug.
LEARNER-1896
parent
2c2aa903
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
11 deletions
+35
-11
openedx/core/djangoapps/waffle_utils/__init__.py
+24
-11
openedx/core/djangoapps/waffle_utils/tests/test_init.py
+11
-0
No files found.
openedx/core/djangoapps/waffle_utils/__init__.py
View file @
7e8566b4
...
...
@@ -193,24 +193,29 @@ class WaffleFlagNamespace(WaffleNamespace):
If check_before_waffle_callback returns None, or if it is not supplied,
then waffle is used to check the flag.
Important: Caching for the check_before_waffle_callback must be handled
by the callback itself.
Arguments:
flag_name (String): The name of the flag to check.
check_before_waffle_callback (function): (Optional) A function that
will be checked before continuing on to waffle. If
check_before_waffle_callback(namespaced_flag_name) returns True
or False, it is
cached and returned. If it returns None, then
waffle is
used.
or False, it is
returned. If it returns None, then waffle is
used.
flag_undefined_default (Boolean): A default value to be returned if
the waffle flag is to be checked, but doesn't exist.
"""
# validate arguments
namespaced_flag_name
=
self
.
_namespaced_name
(
flag_name
)
value
=
self
.
_cached_flags
.
get
(
namespaced_flag_name
)
if
value
is
None
:
if
check_before_waffle_callback
:
value
=
check_before_waffle_callback
(
namespaced_flag_name
)
if
check_before_waffle_callback
:
value
=
check_before_waffle_callback
(
namespaced_flag_name
)
if
value
is
None
:
# Do not get cached value for the callback, because the key might be different.
# The callback needs to handle its own caching if it wants it.
value
=
self
.
_cached_flags
.
get
(
namespaced_flag_name
)
if
value
is
None
:
if
flag_undefined_default
is
not
None
:
...
...
@@ -223,7 +228,7 @@ class WaffleFlagNamespace(WaffleNamespace):
if
value
is
None
:
value
=
flag_is_active
(
get_request
(),
namespaced_flag_name
)
self
.
_cached_flags
[
namespaced_flag_name
]
=
value
self
.
_cached_flags
[
namespaced_flag_name
]
=
value
return
value
...
...
@@ -264,12 +269,12 @@ class CourseWaffleFlag(WaffleFlag):
Uses a cached waffle namespace.
"""
def
_get_course_override_callback
(
self
,
course_
id
):
def
_get_course_override_callback
(
self
,
course_
key
):
"""
Returns a function to use as the check_before_waffle_callback.
Arguments:
course_
id
(CourseKey): The course to check for override before
course_
key
(CourseKey): The course to check for override before
checking waffle.
"""
def
course_override_callback
(
namespaced_flag_name
):
...
...
@@ -277,17 +282,25 @@ class CourseWaffleFlag(WaffleFlag):
Returns True/False if the flag was forced on or off for the provided
course. Returns None if the flag was not overridden.
Note: Has side effect of caching the override value.
Arguments:
namespaced_flag_name (String): A namespaced version of the flag
to check.
"""
force_override
=
WaffleFlagCourseOverrideModel
.
override_value
(
namespaced_flag_name
,
course_id
)
cache_key
=
u'{}.{}'
.
format
(
namespaced_flag_name
,
unicode
(
course_key
))
force_override
=
self
.
waffle_namespace
.
_cached_flags
.
get
(
cache_key
)
if
force_override
is
None
:
force_override
=
WaffleFlagCourseOverrideModel
.
override_value
(
namespaced_flag_name
,
course_key
)
self
.
waffle_namespace
.
_cached_flags
[
cache_key
]
=
force_override
if
force_override
==
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
on
:
return
True
if
force_override
==
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
off
:
return
False
return
None
return
course_override_callback
def
is_enabled
(
self
,
course_key
=
None
):
...
...
@@ -299,7 +312,7 @@ class CourseWaffleFlag(WaffleFlag):
checking waffle.
"""
# validate arguments
assert
issubclass
(
type
(
course_key
),
CourseKey
),
"The course_
id
'{}' must be a CourseKey."
.
format
(
assert
issubclass
(
type
(
course_key
),
CourseKey
),
"The course_
key
'{}' must be a CourseKey."
.
format
(
str
(
course_key
)
)
...
...
openedx/core/djangoapps/waffle_utils/tests/test_init.py
View file @
7e8566b4
...
...
@@ -23,6 +23,7 @@ class TestCourseWaffleFlag(TestCase):
NAMESPACED_FLAG_NAME
=
NAMESPACE_NAME
+
"."
+
FLAG_NAME
TEST_COURSE_KEY
=
CourseKey
.
from_string
(
"edX/DemoX/Demo_Course"
)
TEST_COURSE_2_KEY
=
CourseKey
.
from_string
(
"edX/DemoX/Demo_Course_2"
)
TEST_NAMESPACE
=
WaffleFlagNamespace
(
NAMESPACE_NAME
)
TEST_COURSE_FLAG
=
CourseWaffleFlag
(
TEST_NAMESPACE
,
FLAG_NAME
)
...
...
@@ -50,6 +51,16 @@ class TestCourseWaffleFlag(TestCase):
self
.
TEST_COURSE_KEY
)
# check flag for a second course
if
data
[
'course_override'
]
==
WaffleFlagCourseOverrideModel
.
ALL_CHOICES
.
unset
:
# When course override wasn't set for the first course, the second course will get the same
# cached value from waffle.
self
.
assertEqual
(
self
.
TEST_COURSE_FLAG
.
is_enabled
(
self
.
TEST_COURSE_2_KEY
),
data
[
'waffle_enabled'
])
else
:
# When course override was set for the first course, it should not apply to the second
# course which should get the default value of False.
self
.
assertEqual
(
self
.
TEST_COURSE_FLAG
.
is_enabled
(
self
.
TEST_COURSE_2_KEY
),
False
)
@ddt.data
(
{
'flag_undefined_default'
:
None
,
'result'
:
False
},
{
'flag_undefined_default'
:
False
,
'result'
:
False
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment