ol-openedx-git-auto-export 0.8.2__tar.gz → 0.8.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/.gitignore +3 -0
  2. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/PKG-INFO +1 -1
  3. ol_openedx_git_auto_export-0.8.3/ol_openedx_git_auto_export/exceptions.py +15 -0
  4. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/settings/common.py +3 -0
  5. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/settings/production.py +3 -0
  6. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/signals.py +18 -3
  7. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/tasks.py +18 -2
  8. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/utils.py +22 -5
  9. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/pyproject.toml +1 -1
  10. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/CHANGELOG.rst +0 -0
  11. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/LICENSE +0 -0
  12. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/README.rst +0 -0
  13. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/__init__.py +0 -0
  14. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/admin.py +0 -0
  15. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/app.py +0 -0
  16. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/constants.py +0 -0
  17. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/management/commands/__init__.py +0 -0
  18. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/management/commands/migrate_giturl.py +0 -0
  19. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/migrations/0001_initial.py +0 -0
  20. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/migrations/0002_contentgitrepository.py +0 -0
  21. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/migrations/__init__.py +0 -0
  22. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/models.py +0 -0
  23. {ol_openedx_git_auto_export-0.8.2 → ol_openedx_git_auto_export-0.8.3}/ol_openedx_git_auto_export/settings/__init__.py +0 -0
@@ -12,3 +12,6 @@ ol_test_requirements.txt
12
12
  **/.coverage
13
13
  **/test_root
14
14
  coverage.xml
15
+
16
+ # Claude
17
+ .claude/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ol-openedx-git-auto-export
3
- Version: 0.8.2
3
+ Version: 0.8.3
4
4
  Summary: A plugin that auto saves the course OLX to git when an author publishes it
5
5
  Author: MIT Office of Digital Learning
6
6
  License-Expression: BSD-3-Clause
@@ -0,0 +1,15 @@
1
+ """
2
+ Custom exceptions for the ol_openedx_git_auto_export app.
3
+ """
4
+
5
+
6
+ class ContentNotFoundError(Exception):
7
+ """
8
+ Raised when a course or library cannot be found via the modulestore or
9
+ the content_libraries API.
10
+
11
+ This is expected to happen transiently right after a course/library is
12
+ created: the creation signal (e.g. CONTENT_LIBRARY_CREATED) can fire
13
+ before the DB transaction that wrote the row has committed, so an async
14
+ Celery task racing against that commit finds nothing.
15
+ """
@@ -16,6 +16,9 @@ def plugin_settings(settings):
16
16
  )
17
17
  settings.GITHUB_ORG_API_URL = env_tokens.get("GITHUB_ORG_API_URL", "")
18
18
  settings.GITHUB_ACCESS_TOKEN = env_tokens.get("GITHUB_ACCESS_TOKEN")
19
+ settings.GIT_AUTO_EXPORT_AUTHORING_URL_PREFIX = env_tokens.get(
20
+ "GIT_AUTO_EXPORT_AUTHORING_URL_PREFIX", "authoring"
21
+ )
19
22
 
20
23
  # Course-specific settings
21
24
  settings.FEATURES[ENABLE_GIT_AUTO_EXPORT] = env_tokens.get("FEATURES", {}).get(
@@ -16,6 +16,9 @@ def plugin_settings(settings):
16
16
  )
17
17
  settings.GITHUB_ORG_API_URL = env_tokens.get("GITHUB_ORG_API_URL", "")
18
18
  settings.GITHUB_ACCESS_TOKEN = env_tokens.get("GITHUB_ACCESS_TOKEN")
19
+ settings.GIT_AUTO_EXPORT_AUTHORING_URL_PREFIX = env_tokens.get(
20
+ "GIT_AUTO_EXPORT_AUTHORING_URL_PREFIX", "authoring"
21
+ )
19
22
 
20
23
  # Course-specific settings
21
24
  settings.FEATURES[ENABLE_GIT_AUTO_EXPORT] = env_tokens.get("FEATURES", {}).get(
@@ -9,6 +9,7 @@ export content to them.
9
9
  import logging
10
10
 
11
11
  from common.djangoapps.course_action_state.models import CourseRerunState
12
+ from django.db import transaction
12
13
  from django.db.models.signals import post_save
13
14
  from django.dispatch import receiver
14
15
 
@@ -45,7 +46,7 @@ def listen_for_course_created(**kwargs):
45
46
  course_key = kwargs.get("course").course_key
46
47
 
47
48
  if is_auto_repo_creation_enabled():
48
- async_create_github_repo.delay(str(course_key))
49
+ transaction.on_commit(lambda: async_create_github_repo.delay(str(course_key)))
49
50
 
50
51
 
51
52
  @receiver(post_save, sender=CourseRerunState)
@@ -58,7 +59,10 @@ def listen_for_course_rerun_state_post_save(sender, instance, **kwargs): # noqa
58
59
  return
59
60
 
60
61
  if is_auto_repo_creation_enabled():
61
- async_create_github_repo.delay(str(instance.course_key), export_content=True)
62
+ course_key = instance.course_key
63
+ transaction.on_commit(
64
+ lambda: async_create_github_repo.delay(str(course_key), export_content=True)
65
+ )
62
66
 
63
67
 
64
68
  # Library Signal Receivers
@@ -96,7 +100,18 @@ def listen_for_library_v2_created(**kwargs):
96
100
  log.info("Library v2 created signal received for library: %s", library_key)
97
101
 
98
102
  if is_auto_repo_creation_enabled(is_library=True):
99
- async_create_github_repo.delay(str(library_key), export_content=True)
103
+ # CONTENT_LIBRARY_CREATED fires synchronously inside the request's
104
+ # DB transaction (Studio views run with ATOMIC_REQUESTS=True). If we
105
+ # dispatch the Celery task immediately, a worker can query the
106
+ # library (via a separate DB connection) before this transaction
107
+ # commits, raising a spurious "library not found".
108
+ # Deferring the dispatch to on_commit ensures the row is visible
109
+ # by the time the task runs.
110
+ transaction.on_commit(
111
+ lambda: async_create_github_repo.delay(
112
+ str(library_key), export_content=True
113
+ )
114
+ )
100
115
 
101
116
 
102
117
  def listen_for_library_v2_updated(**kwargs):
@@ -13,6 +13,7 @@ from django.conf import settings
13
13
  from opaque_keys.edx.keys import LearningContextKey
14
14
  from rest_framework import status
15
15
 
16
+ from ol_openedx_git_auto_export.exceptions import ContentNotFoundError
16
17
  from ol_openedx_git_auto_export.models import ContentGitRepository
17
18
  from ol_openedx_git_auto_export.utils import (
18
19
  clear_stale_git_lock,
@@ -32,10 +33,18 @@ def async_export_to_git(context_key_string, user=None):
32
33
  context_key_string (str): String representation of LearningContextKey
33
34
  user: Optional user for git export
34
35
  """
35
- # Parse as LearningContextKey to support all learning contexts
36
36
  try:
37
37
  context_key = LearningContextKey.from_string(context_key_string)
38
38
  content_info = get_content_info(context_key)
39
+ except ContentNotFoundError:
40
+ # Expected transiently if this task races the DB transaction that
41
+ # created the content (e.g. dispatched from a signal handler before
42
+ # commit).
43
+ LOGGER.warning(
44
+ "Content %s not found yet; skipping this export attempt. ",
45
+ context_key_string,
46
+ )
47
+ return
39
48
  except Exception:
40
49
  LOGGER.exception("Failed to parse content key: %s", context_key_string)
41
50
  return
@@ -115,6 +124,10 @@ def async_create_github_repo(self, context_key_str, export_content=False): # no
115
124
  try:
116
125
  context_key = LearningContextKey.from_string(context_key_str)
117
126
  content_info = get_content_info(context_key)
127
+ except ContentNotFoundError as exc:
128
+ response_msg = f"Content {context_key_str} not found: {exc}"
129
+ LOGGER.warning(response_msg)
130
+ return False, response_msg
118
131
  except Exception:
119
132
  LOGGER.exception("Failed to parse context key: %s", context_key_str)
120
133
  return False, f"Invalid context key: {context_key_str}"
@@ -129,7 +142,10 @@ def async_create_github_repo(self, context_key_str, export_content=False): # no
129
142
  return False, response_msg
130
143
 
131
144
  # Determine URL path based on content type
132
- url_path = f"{content_info['content_type']}/{context_key_str}"
145
+ url_path = (
146
+ f"{settings.GIT_AUTO_EXPORT_AUTHORING_URL_PREFIX}"
147
+ f"/{content_info['content_type']}/{context_key_str}"
148
+ )
133
149
 
134
150
  # Get display name (v2 libraries use 'title', others use 'display_name')
135
151
  if content_info["is_v2_library"]:
@@ -12,7 +12,10 @@ from django.contrib.auth.models import User
12
12
  from django.core.cache import cache
13
13
  from django.core.exceptions import ImproperlyConfigured
14
14
  from opaque_keys.edx.locator import LibraryLocator, LibraryLocatorV2
15
- from openedx.core.djangoapps.content_libraries.api import get_library
15
+ from openedx.core.djangoapps.content_libraries.api import (
16
+ ContentLibraryNotFound,
17
+ get_library,
18
+ )
16
19
  from xmodule.modulestore.django import modulestore
17
20
 
18
21
  from ol_openedx_git_auto_export.constants import (
@@ -25,6 +28,7 @@ from ol_openedx_git_auto_export.constants import (
25
28
  REPOSITORY_NAME_MAX_LENGTH,
26
29
  ContentType,
27
30
  )
31
+ from ol_openedx_git_auto_export.exceptions import ContentNotFoundError
28
32
 
29
33
  log = logging.getLogger(__name__)
30
34
 
@@ -43,23 +47,36 @@ def get_content_info(content_key):
43
47
  - is_v1_library: Boolean flag
44
48
  - is_v2_library: Boolean flag
45
49
  - is_library: Boolean flag (True if v1 or v2 library)
50
+
51
+ Raises:
52
+ ContentNotFoundError: If the course/library isn't found.
46
53
  """
47
54
  is_v1_library = isinstance(content_key, LibraryLocator)
48
55
  is_v2_library = isinstance(content_key, LibraryLocatorV2)
49
56
 
50
57
  # Get the content module based on type
51
58
  if is_v2_library:
52
- # V2 libraries use content_libraries API
53
- content_module = get_library(content_key)
59
+ # V2 libraries use content_libraries API, which raises
60
+ # ContentLibraryNotFound (a DoesNotExist alias) rather than
61
+ # returning None.
62
+ try:
63
+ content_module = get_library(content_key)
64
+ except ContentLibraryNotFound as exc:
65
+ msg = f"Library {content_key} not found via content_libraries API."
66
+ raise ContentNotFoundError(msg) from exc
54
67
  content_type = ContentType.LIBRARY.value
55
68
  elif is_v1_library:
56
- # V1 libraries use modulestore
57
69
  content_module = modulestore().get_library(content_key)
58
70
  content_type = ContentType.LIBRARY.value
71
+ if content_module is None:
72
+ msg = f"Library {content_key} not found in modulestore."
73
+ raise ContentNotFoundError(msg)
59
74
  else:
60
- # Courses use modulestore
61
75
  content_module = modulestore().get_course(content_key)
62
76
  content_type = ContentType.COURSE.value
77
+ if content_module is None:
78
+ msg = f"Course {content_key} not found in modulestore."
79
+ raise ContentNotFoundError(msg)
63
80
 
64
81
  return {
65
82
  "content_type": content_type,
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ol-openedx-git-auto-export"
3
- version = "0.8.2"
3
+ version = "0.8.3"
4
4
  description = "A plugin that auto saves the course OLX to git when an author publishes it"
5
5
  authors = [{ name = "MIT Office of Digital Learning" }]
6
6
  license = "BSD-3-Clause"