AttributeError: 'NoneType' object has no attribute 'year'

Hi,

Recently, we’ve been receiving the following error on the platform:

AttributeError: 'NoneType' object has no attribute 'year'

Causing the course to not be displayed.

We’ve already checked the course to ensure the dates are correct, but even after changing them, the error persists.

The version we’re using is:
tutor, version 18.1.1

I found this post, but it hasn’t been commented on or resolved.

Is there a way to resynchronize course dates? Or what steps could I take to correct this problem, since I have students currently taking the course.

This could be because sections or subsections do not have a release date.
You can try to use the legacy outline page and check the outline.
To use legacy outline page, you can turn of the waffle flag contentstore.new_studio_mfe.use_new_course_outline_page in {LMS_HOST}/admin/waffle/flag/

1 Like

Hi,

Thanks, I’ll check it out, but in the meantime, I’ll share the script to solve it.

The script searches within blocks of the course where the date is not set and by default sets the date to January 2024.

from xmodule.modulestore.django import modulestore
from opaque_keys.edx.locator import CourseLocator
from xmodule.modulestore.exceptions import ItemNotFoundError
from datetime import datetime
import pytz

store = modulestore()
course_key = CourseLocator.from_string("COURSE_ID")

try:
    course = store.get_course(course_key, revision='draft')
    print(f"Curso encontrado: {course.id}")
except ItemNotFoundError:
    print("Curso no encontrado. Verifica que exista en Studio.")
    exit()

updated_blocks = 0
default_start = datetime(2024, 1, 1, tzinfo=pytz.UTC)

def fix_block_start(block_key):
    global updated_blocks
    try:
        block = store.get_item(block_key, revision='rev-opt-draft-only')
        if getattr(block, 'start', None) is None:
            block.start = default_start
            store.update_item(block, None)
            updated_blocks += 1
            print(f"✅ Corregido: {block.location}")
        for child_key in block.children:
            fix_block_start(child_key)
    except Exception as e:
        print(f"Error con {block_key}: {e}")

fix_block_start(course.location)

print(f"\n✅ Total de bloques corregidos: {updated_blocks}")

Then we copy it into the container and run it.

docker cp fix_course_starts.py $(docker ps -qf "name=tutor_local-cms-1"):/openedx/edx-platform

python manage.py cms shell < fix_course_starts.py

Hi @Anh_Vu_Nguy_n ,

I’ve already tried disabling the flag, and the error persists.

I still appreciate you taking the time to help me. I already shared the script to resolve this issue in a previous post.