Skip to content

Server error when converting a BNF codelists in some situations #2886

@rw251

Description

@rw251

Why are we doing this?

There are situations where attempting to convert a BNF codelist to DM+D results in a 500 server error. If an identical dmd codelist already exists the code should display a banner to the end user with a link to the dmd file. However the code that attempts to get the link fails if there are multiple identical slugs (which can happen as they're only unique to a user or an org).

How will we know when it's done?

The conversion no longer returns an error but instead displays the banner linking back to the existing dmd codelist

What are we doing?

This line fails if there are multiple identical slugs:

dmd_codelist = Handle.objects.get(slug=f"{version.codelist.slug}-dmd").codelist

Instead we should scope it to the user or org, similar (but not identical) to this code here:

owner_query = Q(user=owner) if isinstance(owner, User) else Q(organisation=owner)
existing_handle = Handle.objects.filter(
owner_query & (Q(name=dmd_name) | Q(slug=dmd_slug))
).last()

Metadata

Metadata

Assignees

No one assigned

    Labels

    deck-scrubbingTech debt or other between-initiative tidy-up work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions