Skip to content

fix: do not change url for section pages#2993

Open
zawan-ila wants to merge 5 commits intomasterfrom
anawaz/10832
Open

fix: do not change url for section pages#2993
zawan-ila wants to merge 5 commits intomasterfrom
anawaz/10832

Conversation

@zawan-ila
Copy link
Copy Markdown
Contributor

@zawan-ila zawan-ila commented Apr 14, 2026

What are the relevant tickets?

https://github.com/mitodl/hq/issues/10832

Description (What does it do?)

See comment

How can this be tested?

  1. Create a section page in a site. This is a page with a filename of _index.md (like this) I don't think the studio interface supports building such pages and these are for legacy usage only.
  2. Make some small edit to the page and save
  3. Verify that the page url does not change.
  4. Build the course and verify that the section page renders correctly.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the WebsiteContentDetailSerializer to prevent the automatic renaming of _index files when a page title is changed, and includes a new test case for this behavior. Feedback suggests also excluding the index filename from automatic renaming, as it is also a reserved Hugo filename.

Comment thread websites/serializers.py
Comment on lines +574 to +578
if (
instance.type == CONTENT_TYPE_PAGE
and title
and instance.filename != "_index"
):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The filename index is also a special Hugo filename (used for leaf bundles) and is explicitly listed in CONTENT_FILENAMES_FORBIDDEN. Similar to _index, it should likely be protected from automatic renaming when the title is updated to avoid breaking the page bundle structure.

Suggested change
if (
instance.type == CONTENT_TYPE_PAGE
and title
and instance.filename != "_index"
):
if (
instance.type == CONTENT_TYPE_PAGE
and title
and instance.filename not in ("index", "_index")
):

@pt2302
Copy link
Copy Markdown
Contributor

pt2302 commented Apr 16, 2026

Two questions/comments:

  • what are the ORM001 and ORM002 directives, and what's the purpose of adding external = ["ORM001", "ORM002"] to pyproject.toml?
  • it would be cleaner to move "_index" to a constants file rather than having it inline in the function.

@zawan-ila
Copy link
Copy Markdown
Contributor Author

what are the ORM001 and ORM002 directives, and what's the purpose of adding external = ["ORM001", "ORM002"] to pyproject.toml?

These directives are from drf-lint. This linter is responsible for detecting N+1 queries. ORM001 and ORM002 are rules in the linter.

Since this PR affects serializers.py, the line numbers for some of the existing exceptions added in drf-lint-baseline.json(which contains exceptions for the linter) change, which cause the linter to fail. That is why we add noqas for these. I have now removed the releated lines from drf-lint-baseline.json as well.

Now ruff does not like noqa codes that it can not recognize, in this case ORM001 and ORM002. Thus, we need to tell rust that these are codes for external linting tools with the external directive.

it would be cleaner to move "_index" to a constants file rather than having it inline in the function

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants