afkiwers / inventree_kicad

KiCad EDA conform API endpoint for KiCad's parts library tool. This plugin provides metadata only and requires matching symbol and footprint libraries within the KiCad EDA.
MIT License
38 stars 8 forks source link

"Footprint Parameter Template" overwrite crashes part generation #69

Closed TimGoll closed 9 months ago

TimGoll commented 9 months ago

I have the following part added in InvenTree:

image

And the footprint parameter is set to the following in the Plugin: KiCad Library Endpoint settings:

image

And I have the following Category settings:

image

When I generate the part.json it works fine and is accepted in KiCad. This is the generated JSON:

{
   "id":"4",
   "name":"CL10A225KO8NNNC",
   "symbolIdStr":"Device:C_Small",
   "exclude_from_bom":"False",
   "exclude_from_board":"False",
   "exclude_from_sim":"False",
   "fields":{
      "value":{
         "value":"2.2uF"
      },
      "footprint":{
         "value":"Capacitor_SMD:C_0603_1608Metric",
         "visible":"False"
      },
      "datasheet":{
         "value":"http://10.192.4.217/media/part_files/4/2304140030_Samsung-Electro-Mechanics-CL10A225KO8NNNC_C23630.pdf",
         "visible":"False"
      },
      "reference":{
         "value":"C",
         "visible":"True"
      },
      "description":{
         "value":"16V 2.2uF X5R ±10% 0603  Multilayer Ceramic Capacitors MLCC - SMD/SMT ROHS",
         "visible":"False"
      },
      "keywords":{
         "value":"",
         "visible":"False"
      },
      "InvenTree":{
         "value":"4",
         "visible":"False"
      },
      "Part URL":{
         "value":"http://10.192.4.217/part/4/",
         "visible":"False"
      },
      "Mounting Type":{
         "value":"",
         "visible":"False"
      },
      "Rated Voltage":{
         "value":"16V",
         "visible":"False"
      },
      "Temperature Coefficient":{
         "value":"X5R",
         "visible":"False"
      },
      "Tolerance":{
         "value":"10%",
         "visible":"False"
      }
   }
}

If I try to use the Footprint Parameter Template setting in the categories settings, the generation fails:

image (note that the field I'm using here is the same that I'm using in the plugin settings)

The output is the following:

{
   "error":"TypeError",
   "error_class":"<class 'TypeError'>",
   "detail":"Error details can be found in the admin panel",
   "path":"/plugin/kicad-library-plugin/v1/parts/4.json",
   "status_code":500
}

The detailed error in the logs looks like this:


Traceback (most recent call last):

File "/root/.local/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 1823, in get_prep_value
return int(value)

TypeError: int() argument must be a string, a bytes-like object or a real number, not 'PartParameterTemplate'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "/root/.local/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)

File "/root/.local/lib/python3.10/site-packages/rest_framework/generics.py", line 208, in get
return self.retrieve(request, *args, **kwargs)

File "/root/.local/lib/python3.10/site-packages/rest_framework/mixins.py", line 56, in retrieve
return Response(serializer.data)

File "/root/.local/lib/python3.10/site-packages/rest_framework/serializers.py", line 555, in data
ret = super().data

File "/root/.local/lib/python3.10/site-packages/rest_framework/serializers.py", line 253, in data
self._data = self.to_representation(self.instance)

File "/root/.local/lib/python3.10/site-packages/rest_framework/serializers.py", line 522, in to_representation
ret[field.field_name] = field.to_representation(attribute)

File "/root/.local/lib/python3.10/site-packages/rest_framework/fields.py", line 1838, in to_representation
return method(value)

File "/usr/local/lib/python3.10/site-packages/inventree_kicad/serializers.py", line 304, in get_kicad_fields
"value": self.get_footprint(part),

File "/usr/local/lib/python3.10/site-packages/inventree_kicad/serializers.py", line 177, in get_footprint
footprint = self.get_parameter_value(part, template_id, backup_value=footprint)

File "/usr/local/lib/python3.10/site-packages/inventree_kicad/serializers.py", line 86, in get_parameter_value
parameter = PartParameter.objects.filter(part=part, template__pk=template_id).first()

File "/root/.local/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)

File "/root/.local/lib/python3.10/site-packages/django/db/models/query.py", line 941, in filter
return self._filter_or_exclude(False, args, kwargs)

File "/root/.local/lib/python3.10/site-packages/django/db/models/query.py", line 961, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, args, kwargs)

File "/root/.local/lib/python3.10/site-packages/django/db/models/query.py", line 968, in _filter_or_exclude_inplace
self._query.add_q(Q(*args, **kwargs))

File "/root/.local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1416, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)

File "/root/.local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1435, in _add_q
child_clause, needed_inner = self.build_filter(

File "/root/.local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1370, in build_filter
condition = self.build_lookup(lookups, col, value)

File "/root/.local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1216, in build_lookup
lookup = lookup_class(lhs, rhs)

File "/root/.local/lib/python3.10/site-packages/django/db/models/lookups.py", line 25, in __init__
self.rhs = self.get_prep_lookup()

File "/root/.local/lib/python3.10/site-packages/django/db/models/lookups.py", line 77, in get_prep_lookup
return self.lhs.output_field.get_prep_value(self.rhs)

File "/root/.local/lib/python3.10/site-packages/django/db/models/fields/__init__.py", line 1825, in get_prep_value
raise e.__class__(

TypeError: Field 'id' expected a number but got <PartParameterTemplate: Package Type>.

I hope this is enough information for you to fix the issue. Feel free to ask any further questions.

afkiwers commented 9 months ago

Hi Tim, thank you very much for submitting this issue. I'll have a look at it and keep you posted.

TimGoll commented 9 months ago

I have to say that I really like the addon so far! It was a bit hard to get used to it at first, especially since InvenTree is new to me as well, but I got most things working by now! Thanks for your work.

afkiwers commented 9 months ago

That's awesome feedback, thanks.

Oliver from InvenTree and I try to make it as easy as possible for everyone to use. As far as I know, InvenTree is the only application supporting KiCad's http lib at the moment.

If you have any suggestions for us on how we can improve the instructions to get people up and running even quicker, please let me know.

TimGoll commented 9 months ago

If you have any suggestions for us on how we can improve the instructions to get people up and running even quicker, please let me know.

afkiwers commented 9 months ago

fixed in https://github.com/afkiwers/inventree_kicad/pull/71

TimGoll commented 9 months ago

great work, man!