overhangio / openedx-scorm-xblock

SCORM XBlock for Open edX
GNU Affero General Public License v3.0
37 stars 46 forks source link

Old SCORMs stopped working after upgrading to 18.0.0 #76

Closed igobranco closed 1 month ago

igobranco commented 2 months ago

After upgrading to 18.0.0 we no longer view the old deploy SCORMs. We are using an on-premisses S3 compatible (Ceph) service and not the AWS service.

The change of:

fix: use usage_key instead of block_id as location identifier for scorm data by @Danyal-Faheem in https://github.com/overhangio/openedx-scorm-xblock/pull/71

As inadvertently created this issue, from my analysis it seams because the storage.exists(...) isn't working as expected on our deployment. I don't know if it could affecting other deployments using AWS S3 service.

From the Django documentation:

exists(name)[source] Returns True if a file referenced by the given name already exists in the storage system, or False if the name is available for a new file.

It's written in the docs a file and not a folder. It could work fine from local file storage, but at least on S3 Ceph isn't - storage class: storages.backends.s3boto3.S3Boto3Storage.

Ref: https://docs.djangoproject.com/en/3.2/ref/files/storage/#django.core.files.storage.Storage.exists

Proposal change, that would fix our issue:

     @property
     def extract_folder_base_path(self):
         """
         Path to the folder where packages will be extracted.
         Compute hash of the unique block usage_id and use that as our directory name.
         """
         # For backwards compatibility, we return the old path if the directory exists
-        if self.storage.exists(self.extract_old_folder_base_path):
+        if self.storage.exists(os.path.join(self.extract_old_folder_base_path, self.package_meta["sha1"], self.index_page_path)):
             return self.extract_old_folder_base_path
         sha1 = hashlib.sha1()
         sha1.update(str(self.scope_ids.usage_id).encode())
         hashed_usage_id = sha1.hexdigest()
         return os.path.join(self.scorm_location(), hashed_usage_id)
DawoudSheraz commented 2 months ago

@Danyal-Faheem FYI

pomegranited commented 2 months ago

I'm seeing this error running latest tutor nightly:

2024-06-20 22:41:47,739 WARNING 7 [xblock.plugin] [user None] [ip None] plugin.py:144 - Unable to load XBlock 'scorm'
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.11/site-packages/xblock/plugin.py", line 141, in load_classes
    yield (class_.name, cls._load_class_entry_point(class_))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/xblock/plugin.py", line 70, in _load_class_entry_point
    class_ = entry_point.load()
             ^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2496, in load
    return self.resolve()
           ^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2502, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/openedxscorm/__init__.py", line 1, in <module>
    from .scormxblock import ScormXBlock
  File "/openedx/venv/lib/python3.11/site-packages/openedxscorm/scormxblock.py", line 18, in <module>
    import importlib_resources
ModuleNotFoundError: No module named 'importlib_resources'
igobranco commented 2 months ago

@pomegranited to fix that on our old Open edX version installation we have installed the package importlib-resources==6.4.0 on Tutor config's OPENEDX_EXTRA_PIP_REQUIREMENTS; and double check if you are running it on python 3.8 instead of 3.11.

Danyal-Faheem commented 2 months ago

Hi @igobranco, thank you for reporting this issue and for providing a solution as well. We're looking into it now.

Danyal-Faheem commented 2 months ago

Hi @pomegranited, can you provide steps on how to reproduce this error as well as your specific tutor environment version? I have tried to launch a new instance of tutor 18.0.0-nightly and scorm seems to be working fine for me.

regisb commented 1 month ago

This issue is resolved in v18.0.1, which ships in the (updated) "openedx" Docker image. Please fetch the latest changes with tutor images pull openedx.

(@pomegranited I believe your issue is unrelated. As far as I understand, you should simply update your nightly image.)