Description
Deployment Type
Self-hosted
NetBox Version
v4.3.0
Python Version
3.10
Steps to Reproduce
This issue affects certain schema migrations within NetBox which manipulate data within the database. Some of the affected migrations are:
dcim/0206_load_module_type_profiles
ipam/0080_populate_service_parents
tenancy/0018_contact_group
The migrations may not function correctly if applied to a non-default database (i.e. manage.py migrate --database foo
). This hasn't surfaced as an issue to date, but presents a concern now that support for external databases has been added in NetBox v4.3.0 under #18780.
Expected Behavior
ORM queries made within the context of a migration should always explicitly reference the connection provided by the schema editor. For example:
def migrate_contact_groups(apps, schema_editor):
Contact = apps.get_model('tenancy', 'Contact')
Contact.objects.using(schema_editor.connection.alias).update(...)
Observed Behavior
These queries are being executed without specifying a connection, which results in utilizing the default database.
def migrate_contact_groups(apps, schema_editor):
Contact = apps.get_model('tenancy', 'Contact')
Contact.objects.update(...)