Skip to content

Conversation

@alexbainter
Copy link
Collaborator

Closes #181.

Fixes the issues noted in #181 and another related-ish one I found in the process.

Issues from #181:

  • "First I edited the Name of every schemaref in a schema and hit Save. It created duplicate SchemaRefs."

    • I wasn't able to actually reproduce this, however when I was examining the code to figure out how this might've happened, I realized we were no longer including instance IDs for SchemaRefs or DocumentationItems in the schema management form (probably introduced in Schema management form redesign #153). This means that every time the form is saved, any existing instances of these two models are deleted and new ones are created to replace them, as opposed to simply updating the existing objects. This would explain how duplicate schema refs were created, though I'm still not sure why the originals weren't deleted as with all my local testing. At any rate, I fixed this and added a test to verify it.
    • We were also missing an .all() call on a QuerySet that was masked by the issue above.
  • "Second I tried to delete some of the duplicates. I think if you delete the last one in the list it works but if you delete one in the middle it fails and won't let you save with a blank field?"

    • This was caused by the formset item indicies not being updated correctly in field IDs/names. I fixed this, but we don't really have a way to test this at the moment.
  • "Last thing, the presence of duplicates indicates that you can have duplicate SchemaRefs - which I thought we were trying to avoid"

    • We don't actually enforce uniqueness at the database level but I went ahead and added a check to make sure that when saving a schema, all of its own SchemaRefs must have unique URLs as opposed to just checking all the other existing SchemaRefs in the database. I also added a test to verify it.

Other issue I found and fixed:

  • The Permanent URL form wasn't catching duplicate slugs between one or more SchemaRefs. I fixed this and added a test to verify it.

@alexbainter alexbainter requested a review from lisad February 9, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issues with multiple subforms in schema form

1 participant