Django quiz app: attribute error - python

The error happens when trying to take a quiz. Although the attribute error of my page is the same as in this topic, the solution has not solved my problem.
I've tried the solution mentioned in the topic above but it hasn't solved my problem. I've mixed all the apps in that Django Quiz in one, having the models in the same file and so on. For the moment it has worked properly, and I've been able to manage the settings in the 'admin' page without any problem.
The issue relies on when taking the quiz, I recieve this traceback:
Internal Server Error: /myquiz/take/
Traceback (most recent call last):
File "C:\P4\myapp\models.py", line 359, in user_sitting
sitting = self.get(user=user, quiz=quiz, complete=False)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\query.py", line 387, in get
self.model._meta.object_name
myapp.models.DoesNotExist: Sitting matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\P4\myapp\views.py", line 163, in dispatch
self.quiz)
File "C:\P4\myapp\models.py", line 361, in user_sitting
sitting = self.new_sitting(user, quiz)
File "C:\P4\myapp\models.py", line 339, in new_sitting
questions = ",".join(map(str, questions_set)) + ","
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\query.py", line 258, in __iter__
self._fetch_all()
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\db\models\query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "C:\Python\lib\site-packages\model_utils\managers.py", line 80, in iterator
sub_obj = self._get_sub_obj_recurse(obj, s)
File "C:\Python\lib\site-packages\model_utils\managers.py", line 153, in _get_sub_obj_recurse
node = getattr(obj, rel)
AttributeError: 'int' object has no attribute 'essay_question'
It seems like the problem might be in essay_question model or in Sitting model. However, I can't find an answer to this problem. Here there are the pieces of code I think that are related with the error, but if more are needed just ask (most of the parts remain the same of the Quiz app of Django).
Sitting manager model:
class SittingManager(models.Manager):
def new_sitting(self, user, quiz):
if quiz.random_order is True:
questions_set = quiz.questions_set.all() \
.select_subclasses() \
.order_by('?')
else:
questions_set = quiz.questions_set.all() \
.select_subclasses()
questions_set = questions_set.values_list('id', flat=True)
if questions_set.count() == 0:
raise ImproperlyConfigured('Question set of the quiz is empty. '
'Please configure questions properly')
if quiz.max_questions and quiz.max_questions < questions_set.count():
questions_set = questions_set[:quiz.max_questions]
questions = ",".join(map(str, questions_set)) + ","
new_sitting = self.create(user=user,
quiz=quiz,
question_order=questions,
question_list=questions,
incorrect_questions="",
current_score=0,
complete=False,
user_answers='{}')
return new_sitting
def user_sitting(self, user, quiz):
if quiz.single_attempt is True and self.filter(user=user,
quiz=quiz,
complete=True)\
.exists():
return False
try:
sitting = self.get(user=user, quiz=quiz, complete=False)
except Sitting.DoesNotExist:
sitting = self.new_sitting(user, quiz)
except Sitting.MultipleObjectsReturned:
sitting = self.filter(user=user, quiz=quiz, complete=False)[0]
return sitting
And the QuizTake view:
EDITED
I would appreciate an answer since it's not the same solution of the other similar error with this app. I would provide more needed info and thank you for the help.
.
EDIT 2:
I'm getting this now while trying to get to 'myquiz/take' view:
Internal Server Error: /myquiz/take/
Traceback (most recent call last):
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\core\handlers\base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "C:\P4\myapp\views.py", line 171, in dispatch
return super(QuizTake, self).dispatch(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\edit.py", line 213, in get
return self.render_to_response(self.get_context_data())
File "C:\P4\myapp\views.py", line 206, in get_context_data
context = super(QuizTake, self).get_context_data(**kwargs)
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\edit.py", line 122, in get_context_data
kwargs['form'] = self.get_form()
File "C:\Python\lib\site-packages\django-1.9.1-py3.5.egg\django\views\generic\edit.py", line 35, in get_form_with_form_class
return get_form(self, form_class=form_class)
File "C:\P4\myapp\views.py", line 184, in get_form
return form_class(**self.get_form_kwargs())
TypeError: __init__() missing 1 required positional argument: 'question'
Here are extracts of my views.py (which seem to be causing the error):
def dispatch(self, request, *args, **kwargs):
self.quiz = get_object_or_404(Quiz, url=self.kwargs['quiz_name'])
if self.quiz.draft and not request.user.has_perm('quiz.change_quiz'):
raise PermissionDenied
self.logged_in_user = self.request.user.is_authenticated()
if self.logged_in_user:
self.sitting = Sitting.objects.user_sitting(request.user,
self.quiz)
else:
self.sitting = self.anon_load_sitting()
if self.sitting is False:
return render(request, 'single_complete.html')
return super(QuizTake, self).dispatch(request, *args, **kwargs)
Get_form:
def get_form(self, form_class):
if self.logged_in_user:
self.questions = self.sitting.get_first_questions()
self.progress = self.sitting.progress()
else:
self.questions = self.anon_next_questions()
self.progress = self.anon_sitting_progress()
if self.questions.__class__ is Essay_Questions:
form_class = EssayForm
return form_class(**self.get_form_kwargs())
def get_form_kwargs(self):
kwargs = super(QuizTake, self).get_form_kwargs()
return dict(kwargs, questions=self.questions)
FORM_VALID and get_context_data
def form_valid(self, form):
if self.logged_in_user:
self.form_valid_user(form)
if self.sitting.get_first_questions() is False:
return self.final_result_user()
else:
self.form_valid_anon(form)
if not self.request.session[self.quiz.anon_q_list()]:
return self.final_result_anon()
self.request.POST = {}
return super(QuizTake, self).get(self, self.request)
def get_context_data(self, **kwargs):
context = super(QuizTake, self).get_context_data(**kwargs)
context['question'] = self.questions
context['quiz'] = self.quiz
if hasattr(self, 'previous'):
context['previous'] = self.previous
if hasattr(self, 'progress'):
context['progress'] = self.progress
return context

myapp.models.DoesNotExist: Sitting matching query does not exist.
This means exactly what it says. YOu are trying to fetch a Sitting object that does not exist. So you need to sorround line 359 with try except to handle that situation cleanly. In fact you can simplify that whole method as follows.
def user_sitting(self, user, quiz):
if quiz.single_attempt is True and self.filter(user=user,
quiz=quiz,
complete=True)\
.exists():
return False
try:
return self.filter(user=user,quiz=quiz,complete=True)[0]
except IndexError:
return sitting = self.new_sitting(user, quiz)
Simpler code is easier to maintain and you are cutting down the number of queries, which leads to a performance improvement.
AttributeError: 'int' object has no attribute 'essay_question'
What this means is that you think you h have a Questions instance but what you actually have is a meta. The rest of the stacktrace gives you the lines of execution that lead to this error. Look at the lines that mention your own code, some where near they you are calling a method that should return a Questions instance but returns int instead.
The reason that it used to work and doesn't work anymore is what's known as a regression error. Changes to some section of code has made another section misbehave. The most popular, sustainable way to tackle them is with unit testing.

Related

Telegram Bot Getting User Phone Number

I have an issue with my bot:
I want to authorize user via phone_request. But it crashes. Although I get user phone. By phone_request I mean that I'm asking user for a phone number with this:
def get_keyboard():
contact_button = KeyboardButton('Start conversation',
request_contact=True)
reply_keyboard = [[contact_button]]
return reply_keyboard
I catch it with this:
dp.add_handler(MessageHandler(Filters.contact,
contact_callback,pass_user_data=True))
Than it goes there:
def contact_callback(bot, update):
contact = update.effective_message.contact
phone = contact.phone_number
print(contact)
print(phone)
update.message.reply_text('Thanks your data is accepted', get_authorized(), resize_keyboard=True)
get_authorized is simply this:
def get_authorized():
reply_keyboard = [['Pay', 'Why I'm in debt'], ['Remind Later']]
return reply_keyboard
What can go wrong here?
Traceback:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/telegram/ext/dispatcher.py", line 279, in process_update
handler.handle_update(update, self)
File "/usr/local/lib/python3.5/dist-packages/telegram/ext/messagehandler.py", line 169, in handle_update
return self.callback(dispatcher.bot, update, **optional_args)
File "/home/ubuntu/Telegram_bot_OSDI/Telegram_Bot_OSDI_22.py", line 164, in contact_callback
update.message.reply_text('Спасибо! Ваши данные приняты', get_authorized(), resize_keyboard=True)
File "/usr/local/lib/python3.5/dist-packages/telegram/message.py", line 455, in reply_text
return self.bot.send_message(self.chat_id, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/telegram/bot.py", line 65, in decorator
result = func(self, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/telegram/bot.py", line 90, in decorator
result = self._request.post(url, data, timeout=kwargs.get('timeout'))
File "/usr/local/lib/python3.5/dist-packages/telegram/utils/request.py", line 309, in post
headers={'Content-Type': 'application/json'})
File "/usr/local/lib/python3.5/dist-packages/telegram/utils/request.py", line 223, in _request_wrapper
raise BadRequest(message)
telegram.error.BadRequest: Unsupported parse_mode

AttributeError: 'int' object has no attribute 'id' - Odoo v9 community

I've migrated a module which can create stock.inventory movements, by uploading csv's.
It's functioning quite good, but sometimes, when I upload certain csv's, it throws me this error:
Odoo
Odoo Server Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 892, in call_button
action = self._call_kw(model, method, args, {})
File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 880, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 421, in old_api
result = new_api(recs, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 425, in new_api
result = [method(rec, *args, **kwargs) for rec in self]
File "/usr/lib/python2.7/dist-packages/openerp/custom_addons/stock_inventory_import/wizard/import_inventory.py", line 85, in action_import
val['location_id'] = prod_location.id
AttributeError: 'int' object has no attribute 'id'
The code is this:
#api.one
def action_import(self):
"""Load Inventory data from the CSV file."""
ctx = self._context
stloc_obj = self.env['stock.location']
inventory_obj = self.env['stock.inventory']
inv_imporline_obj = self.env['stock.inventory.import.line']
product_obj = self.env['product.product']
if 'active_id' in ctx:
inventory = inventory_obj.browse(ctx['active_id'])
if not self.data:
raise exceptions.Warning(_("You need to select a file!"))
# Decode the file data
data = base64.b64decode(self.data)
file_input = cStringIO.StringIO(data)
file_input.seek(0)
location = self.location
reader_info = []
if self.delimeter:
delimeter = str(self.delimeter)
else:
delimeter = ','
reader = csv.reader(file_input, delimiter=delimeter,
lineterminator='\r\n')
try:
reader_info.extend(reader)
except Exception:
raise exceptions.Warning(_("Not a valid file!"))
keys = reader_info[0]
# check if keys exist
if not isinstance(keys, list) or ('code' not in keys or
'quantity' not in keys):
raise exceptions.Warning(
_("Not 'code' or 'quantity' keys found"))
del reader_info[0]
values = {}
actual_date = fields.Date.today()
inv_name = self.name + ' - ' + actual_date
inventory.write({'name': inv_name,
'date': fields.Datetime.now(),
'imported': True, 'state': 'confirm'})
for i in range(len(reader_info)):
val = {}
field = reader_info[i]
values = dict(zip(keys, field))
prod_location = location.id
if 'location' in values and values['location']:
locat_lst = stloc_obj.search([('name', '=',
values['location'])])
if locat_lst:
prod_location = locat_lst[0]
prod_lst = product_obj.search([('default_code', '=',
values['code'])])
if prod_lst:
val['product'] = prod_lst[0].id
if 'lot' in values and values['lot']:
val['lot'] = values['lot']
val['code'] = values['code']
val['quantity'] = values['quantity']
val['location_id'] = prod_location.id
val['inventory_id'] = inventory.id
val['fail'] = True
val['fail_reason'] = _('No processed')
inv_imporline_obj.create(val)
And the csv's look like this:
id product_id reference code combinacion avanzadastock location quantity qty
2780 Piloto trasero Recambio Ecológico Original M0002780 gsx 600 f 600 1988-1991/4316/A8I 1
This error appears from time to time, often it just works without problems, but some other times throws this error.
It is exactly on location column.
I have csv's with more than 5k items, so it's difficult for me to track the error.
Is this csv related? Or it is a matter of code?
Issue is your logic
prod_location = location.id
Then the following if statement is never entered, and you move to
val['location_id'] = prod_location.id
And the error is thrown
Yes correct. Some location don't exist on the system. That's it throws error. To avoid such error, you can use following trick.
prod_location = self.location and self.location.id or False
Means if system has location then prod_location variable set value with id of location otherwise False
NOTE:
In model declaration, location_id field set with required=False otherwise you can not create record with location_id=False It will give you integrity error.
Actually the problem was the csv content
Because some locations don't exist on the system, then it throws out that error.
So, need to check for locations that do exist before continuing with the process.
Thank You.

Odoo. TypeError: 'int' object is not iterable

I have problrem with my code.
class SiteTrip(models.Model):
_name = 'vips_vc.site_trip'
name = fields.Char()
session_ids = fields.One2many('vips_vc.session', 'site_trip_id', string='Session ID', index=True)
url_prevouse_ids = fields.Many2one('vips_vc.url_list', string='Prevouse URL', index=True)
url_current_ids = fields.Many2one('vips_vc.url_list', string='Current URL', index=True)
class URLList(models.Model):
_name = 'vips_vc.url_list'
name = fields.Char(string="URL", required=True)
url_parametes = fields.Char(string="URL parameters")
target_session_id = fields.One2many('vips_vc.session', 'target_url_ids', string='Target URL')
site_trip_prevouse_id = fields.One2many('vips_vc.site_trip', 'url_prevouse_ids', string='Prevouse URL')
site_trip_current_id = fields.One2many('vips_vc.site_trip', 'url_current_ids', string='Current URL')
remote_sites_id = fields.One2many('vips_vc.remote_sites', 'site_url_ids', string='Remote site page with URL')
remote_sites_target_url_id = fields.One2many('vips_vc.remote_sites', 'target_url_ids', string='URL on remote site page')
My controller:
def register_trip(self, currentURLid, prevouseURLid, sessionID):
currentURLid = int(currentURLid)
prevouseURLid = int(prevouseURLid)
result = None
### something
_logger.info("CREATE -----> session_ids: %r url_prevouse_ids: %r url_current_ids: %r",
sessionID, prevouseURLid, currentURLid)
result = table.create({'session_ids': sessionID, 'url_prevouse_ids': prevouseURLid,
'url_current_ids': currentURLid})
### something
return result.id
And error is:
2016-08-04 17:20:52,931 24261 INFO odoov8 openerp.addons.vips_vc.controllers: CREATE -----> session_ids: 59 url_prevouse_ids: 8 url_current_ids: 1
2016-08-04 17:20:52,938 24261 ERROR odoov8 openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
File "/home/skif/odoo/openerp/http.py", line 540, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/skif/odoo/openerp/http.py", line 577, in dispatch
result = self._call_function(**self.params)
File "/home/skif/odoo/openerp/http.py", line 313, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/skif/odoo/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/skif/odoo/openerp/http.py", line 310, in checked_call
return self.endpoint(*a, **kw)
File "/home/skif/odoo/openerp/http.py", line 806, in __call__
return self.method(*args, **kw)
File "/home/skif/odoo/openerp/http.py", line 406, in response_wrap
response = f(*args, **kw)
File "/home/skif/odoo/my-modules/vips_vc/controllers.py", line 194, in register_session
self.register_trip(currentURLid, prevouseURLid, sessionID)
File "/home/skif/odoo/my-modules/vips_vc/controllers.py", line 375, in register_trip
'url_current_ids': currentURLid})
File "/home/skif/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/home/skif/odoo/openerp/models.py", line 4094, in create
record = self.browse(self._create(old_vals))
File "/home/skif/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/home/skif/odoo/openerp/api.py", line 508, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/home/skif/odoo/openerp/models.py", line 4279, in _create
result += self._columns[field].set(cr, self, id_new, field, vals[field], user, rel_context) or []
File "/home/skif/odoo/openerp/osv/fields.py", line 795, in set
for act in values:
TypeError: 'int' object is not iterable
As you see when I'm trying to add record in vips_vc.site_trip i receive error. And error only for currentURLid. It has integer value. prevouseURLid has integer value too. prevouseURLid and currentURLid have similar relation One2Many/Many2One.
prevouseURLid is working. currentURLid isn't.
In this line I checked all param(logger output):
2016-08-04 17:20:52,931 24261 INFO odoov8 openerp.addons.vips_vc.controllers: CREATE -----> session_ids: 59 url_prevouse_ids: 8 url_current_ids: 1
url_prevouse_ids and url_current_ids have type is integer. They have defined value. They have similar relation. And insert url_current_ids return error.
Why is it happening?
Tomorrow all worked fine !
I did not touch relation. I did not touch type of variables...
UPD: After all manipulation I have this: If i'm trying to create record with any param (sessionID, prevouseURLid, currentURLid) I receiving same error: TypeError: 'int' object is not iterable
I found error.
I don't know how it working early...
result = table.create({'session_ids': sessionID, 'url_prevouse_ids': prevouseURLid,
'url_current_ids': currentURLid})
Here present ID record from other tables(models). When I removed all data (module was remove and install again).
After that step by step i check all data what received variables and stored in DB. I founded that vips_vc.url_list and vips_vc.session had not data.
after that i placed such code after create all records:
_logger.info(".....> Commit record ID %r", result.id)
table.env.cr.commit()
I have no idea why it code work early without commit().

Django Admin crash when trying to delete an object

I have a problem where Django Admin (I run Django 1.3) crashes whenever I try to delete an object and the admin tries to display what child objects will be affected by the action. I'm able to delete the object fine in the terminal. This is the traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/options.py", line 307, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/cache.py", line 79, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/sites.py", line 197, in inner
return view(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 28, in _wrapper
return bound_func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 24, in bound_func
return func(self, *args2, **kwargs2)
File "/usr/lib/python2.7/dist-packages/django/db/transaction.py", line 217, in inner
res = func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/options.py", line 1201, in delete_view
[obj], opts, request.user, self.admin_site, using)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/util.py", line 104, in get_deleted_objects
to_delete = collector.nested(format_callback)
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/util.py", line 158, in nested
roots.extend(self._nested(root, seen, format_callback))
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/util.py", line 141, in _nested
children.extend(self._nested(child, seen, format_callback))
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/util.py", line 141, in _nested
children.extend(self._nested(child, seen, format_callback))
File "/usr/lib/python2.7/dist-packages/django/contrib/admin/util.py", line 136, in _nested
if obj in seen:
File "/test.py", line 371, in __eq__
return len(self.text) == len(other.text)
AttributeError: 'ChildB' object has no attribute 'text'
This is what my models look like:
class Parent(models.Model): pass
class ChildA(models.Model):
parent = models.ForeignKey(Parent)
text = models.CharField()
def __eq__(self, other):
return len(self.text) == len(other.text)
class ChildB(models.Model):
parent = models.ForeignKey(Parent)
counter = models.IntegerField()
Why does Django Admin try to compare ChildA and ChildB? I've fixed the issue by adding a check to make sure it's the right type before comparing text length but wondering if anyone else have had this problem and if there is an issue with my structure here. Even more strange is that this doesn't happen for all parent objects.
Thanks, Mattias
models are not correct
from django.db import models
class Parent(models.Model):
pass
class ChildA(models.Model):
parent = models.ForeignKey(Parent)
text = models.CharField()
def __eq__(self, other):
return len(self.text) == len(other.text)
class ChildB(models.Model):
parent = models.ForeignKey(Parent)
counter = models.IntegerField()
The function eq may lead this mistake, mark it and try again
def __eq__(self, other):
return len(self.text) == len(other.text)

AttributeError: 'NoneType' object has no attribute 'fields_get' in Openerp

why does this error occurs? is anyone familiar with this error. i got this error when i click any of the tabs eg: sales,purchase,human resource,accounting etc.
Traceback (most recent call last):
File "/home/openERP/src/openerp-server/bin/osv/osv.py", line 122, in wrapper
return f(self, dbname, *args, **kwargs)
File "/home/openERP/src/openerp-server/bin/osv/osv.py", line 176, in execute
res = self.execute_cr(cr, uid, obj, method, *args, **kw)
File "/home/openERP/src/openerp-server/bin/osv/osv.py", line 167, in execute_cr
return getattr(object, method)(cr, uid, *args, **kw)
File "/home/openERP/src/openerp-server/bin/addons/hr/hr_department.py", line 94, in read
res = super(ir_action_window, self).read(cr, uid, select, fields=fields, context=context, load=load)
File "/home/openERP/src/openerp-server/bin/osv/orm.py", line 2944, in read
result = self._read_flat(cr, user, select, fields, context, load)
File "/home/openERP/src/openerp-server/bin/osv/orm.py", line 3064, in _read_flat
res2 = self._columns[f].get(cr, self, ids, f, user, context=context, values=res)
File "/home/openERP/src/openerp-server/bin/osv/fields.py", line 800, in get
res = self._fnct(obj, cr, user, ids, name, self._arg, context)
File "/home/openERP/src/openerp-server/bin/addons/base/ir/ir_actions.py", line 193, in _search_view
fields_from_fields_get = self.pool.get(act.res_model).fields_get(cr, uid, context=context)
AttributeError: 'NoneType' object has no attribute 'fields_get'
It looks like the problem in:
self.pool.get(act.res_model)
It should be the name which you are using _name attributes
Try with
self.pool.get(act.res.model)
self.pool.get(act.res_model) is returning None (because the dictionary pool doesn't have an entry with the key act.res_model).
Therefore, the call .fields_get(...) on that object fails (because None obviously doesn't have such a method, which is what the error message is trying to tell you).

Categories

Resources