Giter VIP home page Giter VIP logo

Comments (3)

cimnine avatar cimnine commented on May 28, 2024

Can you please post an example of a yaml that triggers this behavior?

from netbox-docker.

bdlamprecht avatar bdlamprecht commented on May 28, 2024

Sure, here it is:

https://gist.github.com/bdlamprecht/04ba20b53edc192fdccbbe09550609c7

Although, I've noticed that potentially this only happens when a device_type that I've manually created (through the WebUI or through the API) is then added to the device_types.yml and then the container is brought up again.

This may be an unsupported workflow (manually adding a type then recreating a container), but in reality, should it be?

from netbox-docker.

cimnine avatar cimnine commented on May 28, 2024

I was able to load your device_types.yml two times with no problems.

If you already have data in Netbox that matches one of the initializers, that's a complex problem. Because there are no primary keys (i.e. ids) in the initializers, it's not possible to distinguish the entries precisely. That's why all given attributes must match exactly for an object not to be created again.

If there is just a very tiny difference, then Django will try to create a new object. But in your case there is already an object, that is similar, yet not identical, and therefore Django will try to create a new object. But it fails to do so, as some unique constraint is violated, i.e. because the value for 'model' in combination with the given manufacturer already exists.

I've tried to come up with a solution that circumvents this problem. But there is not one-size-fits-all solution and that solution is therefore bound to fail for other use-cases. That's why I will leave the scripts as they are.

If you want to create an initializer that supports your case, you may want to adjust (clones of) the existing initializers.

The Django method, that you need to handle for your case, is objects.create_or_update(). The solution would be to pass just the parameters, that you want to use for identification, as the main arguments, and all the other parameters as default=:

device_type, created = DeviceType.objects.get_or_create(params.pop('model'), params.pop('slug'), default=params)

from netbox-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.