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

Natural key definitions for Token and various extras models #4131

Merged
merged 7 commits into from Jul 18, 2023

Conversation

glennmatthews
Copy link
Contributor

@glennmatthews glennmatthews commented Jul 17, 2023

Closes: #3974

What's Changed

  • Corrected the natural-key definitions for ComputedField, CustomField, FileAttachment, ImageAttachment, ObjectChange, Relationship, RelationshipAssociation, and Token models.
  • Re-enabled some Relationship/RelationshipAssociation tests that had been disabled during the IPAM Namespaces work.
  • Fixed the problem that while we could do model.objects.get(composite_key=...) and model.objects.filter(composite_key=...), we didn't have code in place for model.objects.exclude(composite_key=...).
  • Similarly, fixed lack of support for Prefix.objects.exclude(prefix=...) and IPAddress.objects.exclude(address=...).

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • n/a Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • n/a Documentation Updates (when adding/changing features)
  • n/a Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@glennmatthews glennmatthews linked an issue Jul 17, 2023 that may be closed by this pull request
5 tasks
Copy link
Contributor

@HanlinMiao HanlinMiao left a comment

Choose a reason for hiding this comment

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

It looks like RequiredRelationshipTestMixin is not inheriting from RelationshipBaseTest. That might be causing the test failure. But otherwise, it looks good.

changes/3974.fixed Outdated Show resolved Hide resolved
@classmethod
def setUpTestData(cls):
cls.location_ct = ContentType.objects.get_for_model(Location)
cls.rack_ct = ContentType.objects.get_for_model(Rack)
cls.vlan_ct = ContentType.objects.get_for_model(VLAN)

cls.locations = Location.objects.all()[:5]
cls.locations = Location.objects.get_for_model(Rack).get_for_model(VLAN)[:5]
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we assert something like len(cls.locations) == 5 or something after this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we should. Since this is a classmethod we can't do self.assertEqual() but I can maybe just add a plain assert?

glennmatthews and others added 3 commits July 18, 2023 08:50
Co-authored-by: Hanlin Miao <46973263+HanlinMiao@users.noreply.github.com>
@glennmatthews
Copy link
Contributor Author

In addressing Ken's feedback, I uncovered that we didn't have a working implementation for exclude(composite_key=...), and in fixing that, found that we also didn't support Prefix.objects.exclude(prefix=...) or IPAddress.objects.exclude(address=...), so I fixed those too.

@itdependsnetworks
Copy link
Contributor

Thanks!!! I appreciate your thoroughness and this really helps me understand what is going on.

Copy link
Contributor

@HanlinMiao HanlinMiao left a comment

Choose a reason for hiding this comment

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

🚢

Copy link
Contributor

@jathanism jathanism left a comment

Choose a reason for hiding this comment

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

Looking pretty sane. Only the one question for that TODO comment. Good to go either way.

in the `get()` case (only) to *not* automatically convert `get(prefix="10.1.1.1/8")` to
`get(network="10.0.0.0", prefix_length=8)', i.e. discard the host bits.

TODO: why *shouldn't* we have similar enforcement on `filter()` and `exclude()`?
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like this TODO was addressed in the code in the places merge_dicts_without_collision is being called? Is that accurate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm referring to the check at lines 265-266 in this function:

            if str(_prefix) != str(prefix):
                raise self.model.DoesNotExist()

There's no equivalent check in the filter() method, so I didn't add it in the exclude() implementation either.

@glennmatthews glennmatthews merged commit 8fa75b3 into next Jul 18, 2023
23 checks passed
@glennmatthews glennmatthews deleted the u/glennmatthews-3974-extras-natural-keys branch July 18, 2023 20:36
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.

Refine natural keys for various Extras models (+ users.Token)
4 participants