mitodl / mitxonline

BSD 3-Clause "New" or "Revised" License
4 stars 2 forks source link

CI failing on main branch (Python tests) #2382

Closed pt2302 closed 4 days ago

pt2302 commented 1 week ago

Expected Behavior

Python tests should be passing.

Current Behavior

Python tests are failing with this error:

/home/runner/work/mitxonline/mitxonline/frontend/staff-dashboard/build System check identified some issues: WARNINGS: ?: (urls.W005) URL namespace 'v1' isn't unique. You may not be able to reverse all URLs in this namespace cms.CoursePage.topics: (fields.W340) null has no effect on ManyToManyField. Migrations for 'courses': courses/migrations/0055_alter_program_availability.py - Alter field availability on program

Just attempting to apply migrations does not resolve this issue.

pdpinch commented 1 week ago

I thought maybe https://github.com/mitodl/mitxonline/pull/2367 would have fixed this?

arslanashraf7 commented 5 days ago

FYI, Anyone who works on this ticket. I was randomly looking at this ticket but it caught my interest. Here are some details I figured out as to why this might be happening.

Our missing migration detection script ./scripts/test/detect_missing_migrations.sh in CI is complaining about a missing migration e.g. Migrations for 'courses': courses/migrations/0055_alter_program_availability.py - Alter field availability on program.


[TEST SUITE] ./scripts/test/detect_missing_migrations.sh
Error: one or more migrations are missing
Migrations for 'courses': courses/migrations/0055_alter_program_availability.py - Alter field availability on program
[TEST SUITE] ./scripts/test/no_auto_migrations.sh

I also looked at the code and there were no new changes in the models after we added the availability field in https://github.com/mitodl/mitxonline/pull/2322.

So why is this migration being generated even without any model changes?

I think the problem propagated like this:

  1. The model is using choices=AVAILABILITY_CHOICES, default=AVAILABILITY_ANYTIME, max_length=255
  2. AVAILABILITY_CHOICES is a constant AVAILABILITY_CHOICES = list(zip(AVAILABILITY_TYPES, AVAILABILITY_TYPES))
  3. Now, this is where the actual problem might be, We are zipping a Set instead of a list on https://github.com/mitodl/mitxonline/blob/main/courses/constants.py#L37 as a choices list. Since sets are unordered so they are sometimes returning anytime and dated with different orders.

Potential Solution:

We should use the list in https://github.com/mitodl/mitxonline/blob/main/courses/constants.py#L37 instead of a set.