Skip to content

Raise a ValidationError for incorrect related slug when importing resources#631

Open
AdrianDAlessandro wants to merge 3 commits intomainfrom
import-fixes
Open

Raise a ValidationError for incorrect related slug when importing resources#631
AdrianDAlessandro wants to merge 3 commits intomainfrom
import-fixes

Conversation

@AdrianDAlessandro
Copy link
Collaborator

Description

This PR prevents incorrect slugs from being ignored when importing to the DB using the Resource classes in io_resources.py

It achieves this by adding a check to the clean method of the ForeignKey and M2M Widget classes. If any of the slugs provided in the import data do not exist, it raises a ValidationError. This error provides a dictionary with the offending field as keys, which renders nicely in the Admin backend.

M2M Example with the following import data

name,description,slug,kind,url,learning_resources
new tool,description,new-tool,tool,,what_is_open_source_software_oss|not-a-slug
Screenshot 2026-03-13 at 16 34 53

ForeignKey Example with the following import data

name,description,slug,language,url,provider
new tool,description,new-tool,en,,not-a-slug
Screenshot 2026-03-13 at 16 36 34

Fixes #630

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Technical work (non-breaking, change which is work as part of a new feature)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass (eg. python -m pytest)
  • The documentation builds and looks OK (eg. mkdocs serve)
  • Pre-commit hooks run successfully (eg. pre-commit run --all-files)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added or an issue has been opened to tackle that in the future. (Indicate issue here: # (issue))

@AdrianDAlessandro AdrianDAlessandro marked this pull request as ready for review March 13, 2026 17:29
@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

The import data ignores incorrect m2m field slugs

1 participant