Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#29347 closed Bug (invalid)

InternalError at /admin/foo/bar/taz/change/ Error in python: TypeError DETAIL: a float is required

Reported by: rvernica Owned by: nobody
Component: contrib.admin Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I get the following error when accessing the detail page of my model in /admin/:

InternalError at /admin/foo/bar/taz/change/

Error in python: TypeError
DETAIL:  a float is required

The model is:

class Bar(models.Model):
    id = models.CharField(max_length=128, primary_key=True)
    modify_date = models.DateTimeField('date modified')
    change_date = models.DateTimeField('date changed')
    a = models.CharField(max_length=61)
    b = models.CharField(max_length=61)

    def __str__(self):
        return "{}:{}".format(self.wafer, self.location)

class BarAdmin(admin.ModelAdmin):
    fields = ('id', 'modify_date', 'change_date', 'a', 'b')
    readonly_fields = ('id', 'modify_date', 'change_date', 'a', 'b')
    list_display = ('id', 'a', 'b', 'modify_date', 'change_date')

The backend is PostgreSQL 10 and the table used by the model is a Foreign Data Wrapper table. The list page works fine, it is just the detail page that is causing issues. Here is the table schema:

CREATE FOREIGN TABLE django.foo_bar (
    id          VARCHAR(128),
    modify_date TIMESTAMP,
    change_date TIMESTAMP,
    a       VARCHAR(61),
    b    VARCHAR(61)
) SERVER filesystem OPTIONS (...);

Here is the complete traceback:

Request Method: GET
Request URL: http://cessna.labs.hpicorp.net:8000/admin/foo/bar/taz/change/

Django Version: 2.0.2
Python Version: 3.6.3
Installed Applications:
['internal.apps.InternalConfig',
 'sers.apps.SersConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.postgres',
 'prettyjson']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

The above exception (Error in python: TypeError
DETAIL:  a float is required
) was the direct cause of the following exception:

File "/usr/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/usr/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py" in wrapper
  574.                 return self.admin_site.admin_view(view)(*args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/contrib/admin/sites.py" in inner
  223.             return view(request, *args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py" in change_view
  1556.         return self.changeform_view(request, object_id, form_url, extra_context)

File "/usr/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper
  62.             return bound_func(*args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view
  142.                     response = view_func(request, *args, **kwargs)

File "/usr/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func
  58.                 return func.__get__(self, type(self))(*args2, **kwargs2)

File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py" in changeform_view
  1450.             return self._changeform_view(request, object_id, form_url, extra_context)

File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py" in _changeform_view
  1471.             obj = self.get_object(request, unquote(object_id), to_field)

File "/usr/lib/python3.6/site-packages/django/contrib/admin/options.py" in get_object
  719.             return queryset.get(**{field.name: object_id})

File "/usr/lib/python3.6/site-packages/django/db/models/query.py" in get
  397.         num = len(clone)

File "/usr/lib/python3.6/site-packages/django/db/models/query.py" in __len__
  254.         self._fetch_all()

File "/usr/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all
  1179.             self._result_cache = list(self._iterable_class(self))

File "/usr/lib/python3.6/site-packages/django/db/models/query.py" in __iter__
  53.         results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)

File "/usr/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql
  1064.             cursor.execute(sql, params)

File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  100.             return super().execute(sql, params)

File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py" in execute
  68.         return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)

File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute_with_wrappers
  77.         return executor(sql, params, many, context)

File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

File "/usr/lib/python3.6/site-packages/django/db/utils.py" in __exit__
  89.                 raise dj_exc_value.with_traceback(traceback) from exc_value

File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py" in _execute
  85.                 return self.cursor.execute(sql, params)

Exception Type: InternalError at /admin/foo/bar/taz/change/
Exception Value: Error in python: TypeError
DETAIL:  a float is required

Change History (4)

comment:1 by Tim Graham, 7 years ago

It's not clear to me that Django is at fault. Have you confirmed that and if so, can you explain what the problem is? Is that error coming from PostgreSQL? I'm not familiar with foreign data wrappers.

comment:2 by Tim Graham, 7 years ago

Resolution: needsinfo
Status: newclosed
Type: UncategorizedBug

comment:3 by rvernica, 7 years ago

You are correct, the exception was coming from PostgreSQL Foreign Data Wrapper which is also written in Python. Django was just propagating the error. It confused me quite a bit since I had not idea where it was braking from Django's trace. Upon seeing the PostgreSQL log, it was all clear. Just for completeness, this is the error trace in PostgreSQL. Sorry for the hassle.

2018-04-23 18:19:17.913 UTC [30] ERROR:  Error in python: TypeError
2018-04-23 18:19:17.913 UTC [30] DETAIL:  Traceback (most recent call last):
	
	  File "/usr/local/lib/python2.7/dist-packages/multicorn-1.3.4.dev0-py2.7-linux-x86_64.egg/multicorn/fsfdw/__init__.py", line 272, in execute
	    return self.items_to_dicts(self.get_items(quals, columns), columns)
	
	  File "/usr/local/lib/python2.7/dist-packages/multicorn-1.3.4.dev0-py2.7-linux-x86_64.egg/multicorn/fsfdw/__init__.py", line 279, in get_items
	    unicode_(qual.value))
	
	  File "/usr/local/lib/python2.7/dist-packages/multicorn-1.3.4.dev0-py2.7-linux-x86_64.egg/multicorn/fsfdw/structuredfs.py", line 373, in from_filename
	    return Item(self, values)
	
	  File "/usr/local/lib/python2.7/dist-packages/multicorn-1.3.4.dev0-py2.7-linux-x86_64.egg/multicorn/fsfdw/structuredfs.py", line 195, in __init__
	    self.mtime = datetime.datetime.fromtimestamp(mtime)
	
	TypeError: a float is required
Last edited 7 years ago by rvernica (previous) (diff)

comment:4 by Tim Graham, 7 years ago

Resolution: needsinfoinvalid
Note: See TracTickets for help on using tickets.
Back to Top