Skip to content

ContentTypeField should use get_by_natural_key() to leverage internal caching #21327

@jeremystretch

Description

@jeremystretch

NetBox Version

v4.5.1

Python Version

3.12

Area(s) of Concern

  • User Interface
  • REST API
  • GraphQL API
  • Python ORM
  • Other

Details

The to_internal_value() method of our custom ContentTypeField currently resolves the reference ContentType using get():

return self.queryset.get(app_label=app_label, model=model)

This should call the manager's get_by_natural_key() method instead, to leverage its built-in caching and avoid redundant queries.

Metadata

Metadata

Assignees

Labels

netboxstatus: acceptedThis issue has been accepted for implementationtype: performanceA concern regarding application performance

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions