Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Change Log
Unreleased
__________

[10.0.0] - 2024-04-04
---------------------
Changed
~~~~~~~
* **Breaking change**: LibraryCollectionData now takes only a LibraryCollectionLocator.
* **Breaking change**: LibraryContainerData now takes only a LibraryContainerLocator.

[9.20.0] - 2025-03-15
---------------------

Expand Down
2 changes: 1 addition & 1 deletion openedx_events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
more information about the project.
"""

__version__ = "9.20.0"
__version__ = "10.0.0"
19 changes: 10 additions & 9 deletions openedx_events/content_authoring/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

import attr
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2
from opaque_keys.edx.locator import (
LibraryCollectionLocator,
LibraryContainerLocator,
LibraryLocatorV2,
LibraryUsageLocatorV2,
)


@attr.s(frozen=True)
Expand Down Expand Up @@ -218,14 +223,12 @@ class LibraryCollectionData:
Data related to a library collection that has changed.

Attributes:
library_key (LibraryLocatorV2): a key that represents a content library.
collection_key (str): identifies the collection within the library's learning package
collection_key (LibraryCollectionLocator): identifies the collection within the library's learning package
background (bool): indicate whether the sender doesn't want to wait for handler to finish execution,
i.e., the handler can run the task in background. By default it is False.
"""

library_key = attr.ib(type=LibraryLocatorV2)
collection_key = attr.ib(type=str)
collection_key = attr.ib(type=LibraryCollectionLocator)
background = attr.ib(type=bool, default=False)


Expand All @@ -235,12 +238,10 @@ class LibraryContainerData:
Data related to a library container that has changed.

Attributes:
library_key (LibraryLocatorV2): a key that represents a content library.
container_key (str): identifies the container within the library's learning package (e.g. unit, section)
container_key (LibraryContainerLocator): identifies the container (e.g. unit, section)
background (bool): indicate whether the sender doesn't want to wait for handler to finish execution,
i.e., the handler can run the task in background. By default it is False.
"""

library_key = attr.ib(type=LibraryLocatorV2)
container_key = attr.ib(type=str)
container_key = attr.ib(type=LibraryContainerLocator)
background = attr.ib(type=bool, default=False)
47 changes: 46 additions & 1 deletion openedx_events/event_bus/avro/custom_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

from ccx_keys.locator import CCXLocator
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2
from opaque_keys.edx.locator import (
LibraryCollectionLocator,
LibraryContainerLocator,
LibraryLocatorV2,
LibraryUsageLocatorV2,
)

from openedx_events.event_bus.avro.types import PYTHON_TYPE_TO_AVRO_MAPPING

Expand Down Expand Up @@ -112,6 +117,44 @@ def deserialize(data: str):
return UsageKey.from_string(data)


class LibraryCollectionLocatorAvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for LibraryCollectionLocator class.
"""

cls = LibraryCollectionLocator
field_type = PYTHON_TYPE_TO_AVRO_MAPPING[str]

@staticmethod
def serialize(obj) -> str:
"""Serialize obj into string."""
return str(obj)

@staticmethod
def deserialize(data: str):
"""Deserialize string into obj."""
return LibraryCollectionLocator.from_string(data)


class LibraryContainerLocatorAvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for LibraryContainerLocator class.
"""

cls = LibraryContainerLocator
field_type = PYTHON_TYPE_TO_AVRO_MAPPING[str]

@staticmethod
def serialize(obj) -> str:
"""Serialize obj into string."""
return str(obj)

@staticmethod
def deserialize(data: str):
"""Deserialize string into obj."""
return LibraryContainerLocator.from_string(data)


class LibraryLocatorV2AvroSerializer(BaseCustomTypeAvroSerializer):
"""
CustomTypeAvroSerializer for LibraryLocatorV2 class.
Expand Down Expand Up @@ -175,6 +218,8 @@ def deserialize(data: str):
CourseKeyAvroSerializer,
CcxCourseLocatorAvroSerializer,
DatetimeAvroSerializer,
LibraryCollectionLocatorAvroSerializer,
LibraryContainerLocatorAvroSerializer,
LibraryLocatorV2AvroSerializer,
LibraryUsageLocatorV2AvroSerializer,
UsageKeyAvroSerializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"name": "LibraryCollectionData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "collection_key",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"name": "LibraryCollectionData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "collection_key",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"name": "LibraryCollectionData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "collection_key",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"name": "LibraryContainerData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "container_key",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"name": "LibraryContainerData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "container_key",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
"name": "LibraryContainerData",
"type": "record",
"fields": [
{
"name": "library_key",
"type": "string"
},
{
"name": "container_key",
"type": "string"
Expand Down
17 changes: 16 additions & 1 deletion openedx_events/event_bus/avro/tests/test_avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
from fastavro.repository.base import SchemaRepositoryError
from fastavro.schema import load_schema
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryUsageLocatorV2
from opaque_keys.edx.locator import (
LibraryCollectionLocator,
LibraryContainerLocator,
LibraryLocatorV2,
LibraryUsageLocatorV2,
)

from openedx_events.event_bus.avro.deserializer import AvroSignalDeserializer, deserialize_bytes_to_event_data
from openedx_events.event_bus.avro.serializer import AvroSignalSerializer, serialize_event_data_to_bytes
Expand Down Expand Up @@ -109,6 +114,10 @@ def generate_test_event_data_for_data_type(data_type): # pragma: no cover
UsageKey: UsageKey.from_string(
"block-v1:edx+DemoX+Demo_course+type@video+block@UaEBjyMjcLW65gaTXggB93WmvoxGAJa0JeHRrDThk",
),
LibraryCollectionLocator: LibraryCollectionLocator.from_string('lib-collection:MITx:reallyhardproblems:col1'),
LibraryContainerLocator: LibraryContainerLocator.from_string(
'lct:MITx:reallyhardproblems:unit:test-container',
),
LibraryLocatorV2: LibraryLocatorV2.from_string('lib:MITx:reallyhardproblems'),
LibraryUsageLocatorV2: LibraryUsageLocatorV2.from_string('lb:MITx:reallyhardproblems:problem:problem1'),
List[int]: [1, 2, 3],
Expand All @@ -125,6 +134,12 @@ def generate_test_event_data_for_data_type(data_type): # pragma: no cover
"block-v1:edx+DemoX+Demo_course+type@video+block@UaEBjyMjcLW65gaTXggB93WmvoxGAJa0JeHRrDThk",
)},
dict[str, LibraryLocatorV2]: {'key': LibraryLocatorV2.from_string('lib:MITx:reallyhardproblems')},
dict[str, LibraryCollectionLocator]: {
'key': LibraryCollectionLocator.from_string('lib-collection:MITx:reallyhardproblems:col1'),
},
dict[str, LibraryContainerLocator]: {
'key': LibraryContainerLocator.from_string('lct:MITx:reallyhardproblems:unit:test-container'),
},
dict[str, LibraryUsageLocatorV2]: {
'key': LibraryUsageLocatorV2.from_string('lb:MITx:reallyhardproblems:problem:problem1'),
},
Expand Down