Saturday, October 27, 2018

Identify failed insert field

Is there anyway to identify which database field update failed,
instead of a generic message like "ValueError: invalid literal for
int() with base 10: ''?

For example, I have the following save():

tempcust = unconfirmedappointment(name=name, ageyrs=ageyrs,
agemnths=agemnths, gender=gender, mobile=phone,
docid=doc,clinicid=clinicobj, seldate=seldate, seltime=slot,
email=email, address=address, city=city, uniquestring=uniquestring,
otp=otp)
tempcust.save()

Apparently one of the values is wrong for the field. But all I get is
the following:

2018-10-28 08:29:48,842 django.request ERROR Internal Server Error:
/clinic/madhav/doctor/4/setappointment
Traceback (most recent call last):
File "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/exception.py",
line 34, in inner
response = get_response(request)
File "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py",
line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/joel/.local/lib/python3.6/site-packages/django/core/handlers/base.py",
line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/joel/myappointments/clinic/views.py", line 896, in setappointment
tempcust.save()
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 718, in save
force_update=force_update, update_fields=update_fields)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 748, in save_base
updated = self._save_table(raw, cls, force_insert, force_update,
using, update_fields)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 831, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/base.py",
line 869, in _do_insert
using=using, raw=raw)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/manager.py",
line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/query.py",
line 1136, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1288, in execute_sql
for sql, params in self.as_sql():
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1241, in as_sql
for obj in self.query.objs
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1241, in <listcomp>
for obj in self.query.objs
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1240, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for
field in fields]
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/sql/compiler.py",
line 1182, in prepare_value
value = field.get_db_prep_save(value, connection=self.connection)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 790, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 785, in get_db_prep_value
value = self.get_prep_value(value)
File "/home/joel/.local/lib/python3.6/site-packages/django/db/models/fields/__init__.py",
line 1807, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: ''

How to trace which field is problematic, other than manually debugging
each variable and seeing if it is non integer? Can django tell me
which field is causing the issue?

Sincerely yours,

Dr Joel G Mathew

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA%3Diw_-5bzYQfCw2BY38rDSS4aFkR48YC-zMDCWbiTDorRs%3DgQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment