python - DoesNotExist: CustomerProfile matching query does not exist -


class customerprofileformcleaner(object):     """     objet centralises validation , normalizing of customer profile fields     should run inside form's clean function     """    ...      def clean_bank_account(self):         ssn = self.form.cleaned_data.get('ssn')         customer = customerprofile.objects.get(ssn=ssn)          bank_account = self.form.cleaned_data.get('bank_account')         bank = self.form.cleaned_data.get('bank')         bank_transit = self.form.cleaned_data.get('bank_transit')         qs = financialprofile.objects.exclude(customer_id=customer.id).filter(             bank=bank,             bank_transit=bank_transit,             bank_account=bank_account)          if qs.count() > 0:             # concatenation of bank transit, bank account , bank             # number must unique. hence, following message             # displayed if in use.             raise validationerror(                 _('the bank, bank transit , bank in use.')             )          if bank not in (none, ''):                 # check bank account format specific banks                 length = settings.loanwolf_bank_accounts_length.get(bank)                 if length:                     if bank_transit not in (none, ''):                         if not bank_account.isnumeric() or length != len(bank_account):                             raise validationerror(                                 _('bank account number must contain %d digits') % length  # noqa                             )                     else:                         raise validationerror(                             _('cannot validate bank account without valid bank transit')  # noqa                         )         return bank_account    ... 

i have class has been moved in loanwolf/core/forms.py (it worked in loanwolf/customer/utils), , use in 2 differents forms.py files, i.e. loanwolf/customers/forms.py , loanwolf/requests/forms.py. hence, natural me put forms.py file , in core of project, because customerprofileformcleaner used in 2 different models. far got error doesnotexist: customerprofile matching query not exist. have fix error?

update :

traceback (most recent call last):   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__     return self.application(environ, start_response)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 170, in __call__     response = self.get_response(request)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 124, in get_response     response = self._middleware_chain(request)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner     response = response_for_exception(request, exc)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 86, in response_for_exception     response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 128, in handle_uncaught_exception     return debug.technical_500_response(request, *exc_info)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django_extensions/management/technical_response.py", line 6, in null_technical_500_response     six.reraise(exc_type, exc_value, tb)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/exception.py", line 39, in inner     response = get_response(request)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response     response = self._get_response(request)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response     response = self.process_exception_by_middleware(e, request)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response     response = wrapped_callback(request, *callback_args, **callback_kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view     return view_func(request, *args, **kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view     return self.dispatch(request, *args, **kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper     return bound_func(*args, **kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 23, in _wrapped_view     return view_func(request, *args, **kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func     return func.__get__(self, type(self))(*args2, **kwargs2)   file "/home/jeremie/projects/credit-24-django/loanwolf/core/views/mixins.py", line 84, in dispatch     return super(staffrestrictedmixin, self).dispatch(request, *args, **kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch     return handler(request, *args, **kwargs)   file "/home/jeremie/projects/credit-24-django/loanwolf/core/views/generic.py", line 315, in post     return super(frontendmixedformview, self).post(request, *args, **kwargs)   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/views/generic/edit.py", line 182, in post     if form.is_valid():   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/forms/forms.py", line 169, in is_valid     return self.is_bound , not self.errors   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/forms/forms.py", line 161, in errors     self.full_clean()   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/forms/forms.py", line 371, in full_clean     self._clean_form()   file "/home/jeremie/projects/credit-24-django/venv/lib/python2.7/site-packages/django/forms/forms.py", line 398, in _clean_form     cleaned_data = self.clean()   file "/home/jeremie/projects/credit-24-django/loanwolf/customers/forms.py", line 108, in clean     v.clean()   file "/home/jeremie/projects/credit-24-django/loanwolf/core/forms.py", line 79, in clean     value = getattr(self, 'clean_%s' % name)()   file "/home/jeremie/projects/credit-24-django/loanwolf/core/forms.py", line 147, in clean_bank_account     ssn = self.form.cleaned_data.get('ssn') attributeerror: 'queryset' object has no attribute 'id' 

and example use struggling class

class externalrequestbaseform(forms.modelform):      # customerproduct     def clean(self):         c = customerprofileformcleaner(self)         c.clean()          cleaned_product_type = self.cleaned_data.get('product_type')          product_choices = dict(settings.loanwolf_product_type_choices).keys()         if cleaned_product_type in product_choices:             if cleaned_product_type == 'regular':                 self.cleaned_data['product'] = self.cleaned_data[                     'from_regular_product']             elif cleaned_product_type == 'special':                 self.cleaned_data['product'] = self.cleaned_data[                     'from_special_product']         else:             validationerror(_('unknown product type'))      def set_required_fields(self):         field in self.fields:             if field in settings.loanwolf_application_staff_required_fields:                 self.fields[field].required = true 

the offending line this, traceback notes:

    customer = customerprofile.objects.get(ssn=ssn) 

your code clean_bank_account() working point looks customer matching ssn. can't find customerprofile matches, errors out.

you'll need to:

1) figure out why customerprofile isn't being found

2) decide if that's appropriate (i.e. shouldn't found) , if 1 isn't found.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -