Skip to content

Fixes #20042: Support Bridge-Interfaces in Interface-Template Import #20082

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

m-hau
Copy link
Contributor

@m-hau m-hau commented Aug 12, 2025

Fixes: #20042

When importing device- or module-types, allow their interface-templates to contain the bridge attribute and properly save it.


The unexpectedly hardest part was finding the right place to hook into the existing process, which in this cases required to create an entirely new hook-point. While developing and testing I also found some other minor bugs in the generalised import validation, and attempted to fix them. Please see the individual commit messages for more information.

This is a first draft to show the general idea and implementation, with a few parts missing and questions/TODOs still open. I would kindly request some first feedback from the more knowledgeable and codebase-familiar people around here, if this is a valid and acceptable way of doing this.

m-hau added 5 commits August 12, 2025 18:45
The related object fields are not covered by the form, so don't pass
any validation before trying to iterate over them and accessing their
elements. Instead of allowing a hard technical error to be raised,
explicitly check that it is indeed a list, and raise a normal validation
error if not.
Elements of the "related objects list" are passed to the
`prep_related_object_data` function before any validation takes place,
with the potential of failing with a hard error. Similar to the "related
objects not list" case explicitly validate the elements general type,
and raise a normal validation error if it isn't a dictionary.
Adding the field to the InterfaceTemplateImportForm is enough. The two
clean_*_type methods are for properly dynamically restricting what
values can be selected.
Related objects are saved in the same order as they are defined in the
input by the user. So related objects with a dependency on another need
to be saved after the related object they depend on. Which means that
when required, the order needs to be changed.

The related object lists are not part of the actual form, and the
individual related-object forms only cover the elements themselves. So
while the re-order should be done at the form-level during the clean-
step, there is no form covering the lists to use for that. Plus should
all errors be reported with their original location/index and not with
the fixed/resorted one, because these are not useful and even confusing
for the user. So the sorting should be done as late as possible, ideally
just before the save.

This adds a new `prep_related_object_list` hook, which gets passed each
list of related objects. This should only be used for modifications to
the list (aka order). Any changes to the individual objects should still
be done using the existing `prep_related_object_data` hook.

The passed list is not the plain list, but an enumerated variant. This
is needed to preserve the original index of the elements independently
from the actual (possibly changed) order the list, so any later detected
errors (for example by the elements form validation) can accurately be
reported back to the user.
Use the new hook to re-sort the interface template list. It is only done
when required to preserve the original order and prevent any unneeded
computation. But even when sorting, it tries its best to preserve as the
original order as much as possible.

The sorting is still done before any validation of the individual
elements, so needs to be able to work with invalid/incomplete/malformed
data. The only guarantee is that we get a list (of something).

It builds a simple dependency graph, uses Kahn's algorithm to create a
topological sorting of it, and applies that to the interface template
list.
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.

Support Bridge-Interfaces in Interface-Template Import
1 participant