Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed Fields with invalid slugs are not converted to valid keys during 2.0 migration #4854

Closed
joewesch opened this issue Nov 27, 2023 · 3 comments · Fixed by #4920
Closed
Assignees
Labels
type: bug Something isn't working as expected
Milestone

Comments

@joewesch
Copy link
Contributor

Environment

  • Nautobot version (Docker tag too if applicable): 1.6.4 -> 2.0.5
  • Python version: 3.10.12
  • Database platform, version: Postgres 14.9
  • Middleware(s):

Steps to Reproduce

  1. On Nautobot 1.6.4 create a computed field with dashes in the slug instead of underscores (e.g. bad-cpf)
  2. Upgrade Nautobot to 2.0
  3. Try and load the GraphQL UI

Expected Behavior

GraphQL UI loads

Observed Behavior

AssertionError: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "cpf_bad-cpf" does not.
@joewesch joewesch added type: bug Something isn't working as expected triage This issue is new and has not been reviewed. labels Nov 27, 2023
@HanlinMiao
Copy link
Contributor

It is the intended behavior of computed field slugs/keys. Changing the dash to underscore should fix the issue.
We should have enforced the pattern in the migrations but for now can you try cpf.key.replace("-", "_") and then cpf.save()

@HanlinMiao HanlinMiao removed the triage This issue is new and has not been reviewed. label Nov 27, 2023
@glennmatthews
Copy link
Contributor

The issue here is at least twofold:

  • Validation of the key for ComputedField, CustomField, and Relationship is only done in clean() so any direct ORM interaction (ComputedField.objects.create() or ComputedField(...).save()) can result in invalid keys being set. Possible fix here: move that enforcement from clean() to save()?
  • When invalid keys are present, the GraphQL UI throws an exception and fails to load; it should instead log a warning/error message to syslog but not prevent the UI from loading at all.

@lampwins
Copy link
Member

lampwins commented Dec 1, 2023

Check if get_or_create() calls save.

@lampwins lampwins added this to the v2.1 milestone Dec 4, 2023
@HanlinMiao HanlinMiao self-assigned this Dec 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Status: Done
4 participants