question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Epic: Fix up all FKs and related names to follow a self-consistent pattern

See original GitHub issue

Proposed Changes

We don’t have a single consistent pattern for foreign key names and (especially) related names on the corresponding reverse relations, for example:

  • Site.powerpanel_set versus Site.rack_groups (pluralization, underscores)
  • PowerFeed.power_panel versus PowerPanel.powerfeeds (underscores)
  • Tenant.rackreservations versus Tenant.route_targets (underscores)

etc.

Fixing this will be a breaking change for the ORM and possibly also for the REST API and/or GraphQL as well, but it’s the right thing to do long-term.

Justification

Tech debt reduction, improved self-consistency and ease of use.

TODO

  • #2960
  • Do the work (to be updated upon completion of spike)

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jathanismcommented, Nov 16, 2022

My proposal as we had discussed before is to use the Meta.verbose_name_plural for the related model and normalize spaces to underscores. For example:

In [1]: RackReservation._meta.verbose_name_plural
Out[1]: 'rack reservations'

In [2]: from nautobot.utilities.utils import slugify_dashes_to_underscores

In [3]: slugify_dashes_to_underscores(RackReservation._meta.verbose_name_plural)
Out[3]: 'rack_reservations''

… and so on.

To me this gives us determinism and consistency and makes it easy to write lint checks if we want to do so.

The only edge cases would be for m2m such as specifying a best practice for when we do not want a related name (e.g. using related_name="+") or where we want an interpolated related name (e.g. related_name="foo_%(model)s_related").

1reaction
gsnider2195commented, Oct 19, 2022

As part of this can we standardize on parent/child relation names for tree objects? django-tree-queries doesn’t give you an option to choose the names for those relationships so anything that’s a django-tree-queries TreeNode is already using parent/children but we have inconsistencies on MPTTModels. For example InventoryItem uses parent/child_items and Region uses parent/children.

Read more comments on GitHub >

github_iconTop Results From Across the Web

v2.0.0 Milestone · GitHub
All GitHub issues in this milestones are only milestone-candidates and subject to ... Fix up all FKs and related names to follow a...
Read more >
3 common foreign key mistakes (and how to avoid them)
Foreign key constraints are important to any SQL database, but they can also cause problems if they're not implemented correctly.
Read more >
Draft: Update feature_category for those features owned by ...
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) I...
Read more >
XXV DAE-BRNS High Energy Physics Symposium 2022
For the present analysis, we have taken up Golden ratio mixing pattern at high scale. This is compatible with the low energy neutrino ......
Read more >
Filled Ultimum Temporum Reboot (lvl 100, epic, 3.5) CLOSED ...
A friend of mine was hoping to have this game, turned back up. ... Your character dies at negative HP's equal to 1...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found