-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
v3.4-beta1: YAML import raises AttributeError exception #11000
Comments
I'm curious whether the expectation from the user perspective is to provide a list of YAML dictionaries, or separate YAML documents representing each object. The YAML loader expects a list of individual documents (separated with |
Obviously my expectation was to be able to provide the data in a single YAML array :-) Anyway, after looking at the code I also tried
(with various different locations of the separators). Always with the same result. The problem seems to originate in the fact that whether you provide a single YAML document or a list of multiple documents (of which a list containing one document as I did in my minimalised exaxmple),
Iterating over the result will always give lists as items, and obviously Personally, I'd flatten the list and iterate over all dictionaries, whether they come in one or several YAML documents. I can't really see the advantage of one or the other structure (maybe I'm missing something, though). I normally provide YAML data in one large document, but there may be data sources that use the multi-document approach. It would be sensible to be able to handle both. |
Just for clarity, the following is the format currently supported:
|
Hm. That is probably not what anyone would expect when YAML is mentioned. It definitely is a very special case that does not make too much sense to me. What I would expect in the first place is a list in one document. That's what most tools using YAML export eject, and it's the canonical output when you give yaml.dump with a datastructure roughly equivalent to a CSV:
results in
The multi-document approach is nothing I see very often in everyday YAML practice. It doesn't hurt to support it, but I obviously didn't even have the idea of trying it. The currently supported notation does, however definitely make more sense than the multi-document form of one list element per document I tried. Anyway, I'd still go for a list of dictionaries. |
I have a suggestion for a minimal code change that would support at least the three variants discussed here:
The above code can handle three variants of YAML structure:
Update: It was still possible to input valid YAML that caused Exceptions. The code now makes sure that what is returned is a list of dictionaries. |
What is feeding my argument as well is that the JSON importer accepts the following data structure:
This is the exact equivalent of the YAML structure
So it really makes sense to support it in addition to the multi-document variant that js supported at the moment. Given the fact that it is currently possible to submit valid YAML structures that cause exceptions trying to parse them |
While I don't have strong feelings either way, if you use Whatever we decide, we should at least support the format that the DeviceType export function exports in, which is currently multiple yaml documents via. dump_all(), so it needs to be changed if we change the format. |
I made an experiment, just to check my own perception (sometimes you live in a strange bubble), and asked a few colleagues what they think of first when they should represent the data structure of multiple records with specific fields as a YAML structure. All of them came up with the 'list of dictionaries' idea, some of them didn't even know that the multi-document approach exists (I did, but it was stored away in some very remote attic of my brain). What's the rationale behind using Anyway, IMHO it makes sense to be tolerant in what you accept and strict in what you emit - so I'd really prefer the approach outlined above of accepting any structure that represents the record structure that needs to be imported. By the way, I tried to import
(with and without the comma between the dictionaries) as JSON input - both were not accepted. So in JSON the only valid form structure is what would, when parsed as YAML (which is possible, JSON usually is valid YAML as well) be represented as
|
This is the same way the device type YAML import has worked for years. |
Never mind - I can adjust to that, my point is just that IMHO it is a quite unusual variant of YAML. The main point of this issue still remains - getting the input format wrong while providing a valid YAML structure should not cause an exception later in the process, but a The current code only checks for YAML validity (a test that all of my input variants passed) in |
NetBox version
v3.4-beta1
Python version
3.8
Steps to Reproduce
Expected Behavior
The data is imported and a new IP address appears in the database
Observed Behavior
An
AttributeError
exception is raised:The text was updated successfully, but these errors were encountered: