Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

SQL Function HOST missing #4

Open
m87carlson opened this issue Aug 27, 2013 · 2 comments
Open

SQL Function HOST missing #4

m87carlson opened this issue Aug 27, 2013 · 2 comments

Comments

@m87carlson
Copy link
Contributor

When I attempt to add a new virtual or physical system with the network information populated (fqdn, ip, hwaddr) the app dumps a stack trace:

Request Method: POST
Request URL: http://localhost:8000/admin/inventory/physicalmachine/21/

Traceback:
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
  366.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
  196.             return view(request, *args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
  25.             return bound_func(*args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
  21.                 return func(self, *args2, **kwargs2)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/transaction.py" in inner
  209.                 return func(*args, **kwargs)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/contrib/admin/options.py" in change_view
  1055.                 self.save_related(request, form, formsets, True)
File "/home/DISCDRIVE/mikec/projects/inv_2/arritranco/inventory/admin.py" in save_related
  52.             self.save_formset(request, form, formset, change=change)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/contrib/admin/options.py" in save_formset
  721.         formset.save()
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/forms/models.py" in save
  497.         return self.save_existing_objects(commit) + self.save_new_objects(commit)
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/forms/models.py" in save_new_objects
  628.             self.new_objects.append(self.save_new(form, commit=commit))
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/forms/models.py" in save_new
  731.             obj.save()
File "/home/DISCDRIVE/mikec/projects/inv_2/arritranco/inventory/models.py" in save
  289.         if nets:
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/models/query.py" in __nonzero__
  130.             iter(self).next()
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/models/query.py" in _result_iter
  118.                 self._fill_cache()
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/models/query.py" in _fill_cache
  875.                     self._result_cache.append(self._iter.next())
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/models/query.py" in iterator
  291.         for row in compiler.results_iter():
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in results_iter
  763.         for rows in self.execute_sql(MULTI):
File "/home/DISCDRIVE/mikec/projects/inv_2/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  818.         cursor.execute(sql, params)

Exception Type: InternalError at /admin/inventory/physicalmachine/21/
Exception Value: current transaction is aborted, commands ignored until end of transaction block

The PostgreSQL servers shows the following notices:

 ERROR:  function host(integer) does not exist at character 263
 HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
 STATEMENT:  SELECT "network_network"."id", "network_network"."desc", "network_network"."ip", "network_network"."first_ip", "network_network"."last_ip", "network_network"."first_ip_int", "network_network"."last_ip_int", "network_network"."size" FROM "network_network" WHERE (HOST("network_network"."first_ip_int") <= 168117295  AND HOST("network_network"."last_ip_int") >= 168117295 ) ORDER BY "network_network"."size" ASC
 ERROR:  current transaction is aborted, commands ignored until end of transaction block
 STATEMENT:  SHOW default_transaction_isolation

I'm guessing a function is not being created

@m87carlson
Copy link
Contributor Author

Not sure it this is the true fix, but to get around the issue, I manually created a function called HOST:

CREATE FUNCTION HOST( ip integer ) returns integer as $$                                                                                                                                               BEGIN                                                                                                                                                                                                  
 return ip;
END;
$$ language plpgsql;

@8la
Copy link
Member

8la commented Aug 28, 2013

Hi Carlson, the thing is that the fields called first_ip_int and last_ip_int are not required to do any conversion.

If you have a look at the network model, it uses the IPy python library to actually do that conversion from ip to int using two methods:

    def _first_ip_int(self):
        """ Returns integer frist network host-ip """
        return IPy.IP(self.ip)[1].int()

    def _last_ip_int(self):
        """ Returns integer last network host-ip """
        return IPy.IP(self.ip)[-2].int()

We have a versión of arritranco under production, so, i think it may work without doing any conversión at data base level on those fields, and you dont have to create that function on the data base.

We will have a look anyway!
Sorry for de inconvenience.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants