Allow a selection of target servertypes for attributes#427
Open
Allow a selection of target servertypes for attributes#427
Conversation
It is currently only possible to select one or none (all) target servertype for attribtues of type relation, supernet and domain. We have a use case where we want to allow some servertypes as target but not all. - serverdb.models.Attribute: Replace FK with ManyToManyField - serverdb.sql_generator: Replace '=' with 'IN' operator - serverdb.query_materializer: Replace '=' with 'ANY' operator - serverdb.query_materializer: Use Django '__in' instead of '=' for ORM - serverdb.admin: Add filter_horizontal widget, remove from readonly_fields - serverdb.admin: Explain what happens if no servertype is selected - serverdb.forms: Adapt validation from is-not-None to queryset .exists() - Add migration to adjust schema and migrate existing data - Adjust fixtures for tests - Adjust db/integrity.sql: Updated to query M2M join table (likely orphaned)
Whilst dropping the attribute_target_servertype_id_check we lost the enforcement via database constraint that domain and supernet must have a target servertype. This is not easily possible anymore because we now have a dedicated table (m2m). While otherwise (e.g. database triggers) are possible a simple validation in the admin form should suffice because this should be the only place where we manage attributes. So we accept the risk that somebody creates them by writing code and by passes this check.
Contributor
Author
|
I will also check that it does not break the DNS views as they rely on the domain attributes. |
Lift database check constraints first and then do the actual migration in a second one to allow reversing the migration. This is required because if we would reverse the migration in one the check constraint breaks it because the column cannot be null. Unfortunately check constraints cannot be deferred.
brainexe
reviewed
Feb 20, 2026
| return template.format(_raw_sql_escape(value)) | ||
|
|
||
|
|
||
| def _target_servertype_sql(alias, attribute): |
Member
There was a problem hiding this comment.
could we use typehint at least for new code, else it's alwas hard to see is the attribute is the plain string or some django model.
brainexe
approved these changes
Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It is currently only possible to select one or none (all) target servertype for attribtues of type relation, supernet and domain.
We have a use case where we want to allow some servertypes as target but not all.