Ralph Asset Management System - User Group

I can't export a list of IP addresses

I can’t export a list of IPs in Ralph (myralph.com/networks/ipaddress/export/?). It gives an error 500 (Server Error (500)). I tried (https://ralph-demo.allegro.tech/networks/ipaddress/export/?) and it’s the same problem.

This is the error in /var/log/nginx/ralph-access.log:

192.168.44.1 - - [18/Sep/2019:09:16:26 +0200] “POST /networks/ipaddress/export/? HTTP/1.1” 500 38 "http://myralph.com/networks/ipaddress/export/?" “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36”

And this is the error in /var/log/ralph/ralph.log:

[18.09.2019 09:57:50,198] ERROR [MainProcess 14922] base - Internal Server Error: /networks/ipaddress/export/
Traceback (most recent call last):
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/core/handlers/base.py”, line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/usr/lib/python3.6/contextlib.py”, line 52, in inner
return func(*args, **kwds)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/utils/decorators.py”, line 110, in _wrapped_view
response = view_func(request, *args, **kwargs)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/views/decorators/cache.py”, line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/contrib/admin/sites.py”, line 233, in inner
return view(request, *args, **kwargs)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/import_export/admin.py”, line 346, in export_action
queryset = self.get_export_queryset(request)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/ralph/admin/mixins.py”, line 422, in get_export_queryset
# sql queries are made to fetch all m2m relations)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py”, line 162, in iter
self._fetch_all()
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py”, line 965, in _fetch_all
self._result_cache = list(self.iterator())
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/query.py”, line 238, in iterator
results = compiler.execute_sql()
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 829, in execute_sql
sql, params = self.as_sql()
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 378, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 48, in pre_sql_setup
self.setup_query()
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 39, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 206, in get_select
related_klass_infos = self.get_related_selections(select)
File “/opt/ralph/ralph-core/lib/python3.6/site-packages/django/db/models/sql/compiler.py”, line 754, in get_related_selections
', '.join(_get_field_choices()) or ‘(none)’,
django.core.exceptions.FieldError: Invalid field name(s) given in select_related: ‘base_object’. Choices are: ethernet, network

It fixed #3449
Closed in 1b315e6

Are you sure it’s fixed? I have the latest version and I still have the same problem.

Version: 1.8.19

You may try to modify your source code in src/ralph/admin/mixins.py

        for name, field in resource.fields.items():
            if (	            
                isinstance(field.widget, ForeignKeyWidget) and	                
                not getattr(field, '_exclude_in_select_related', False) and	               
                not isinstance(getattr(queryset.model, name, None), property)
            ):	  
                fk_fields.append(field.attribute)	           

is exactly how my src/ralph/admin/mixins.py file is.