When I am executing celery task it is giving me:
ValueError: Related model u'user.User' cannot be resolved
The stacktrace is
Traceback (most recent call last):
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/celery/app/trace.py", line 375, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/celery/app/trace.py", line 632, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/prince/work/magneto/set/facebook_pages/tasks.py", line 23, in analyze_page
connected_facebook_page = get_connected_facebook_page(connected_facebook_page_id)
File "/Users/prince/work/magneto/set/facebook_pages/utils.py", line 49, in get_connected_facebook_page
return ConnectedUserPage.objects.get(id=connected_facebook_page_id)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 374, in get
num = len(clone)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 232, in __len__
self._fetch_all()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 876, in execute_sql
sql, params = self.as_sql()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 428, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 46, in pre_sql_setup
self.setup_query()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 37, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 194, in get_select
for c in self.get_default_columns():
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 569, in get_default_columns
column = field.get_col(alias)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1008, in get_col
return super(ForeignKey, self).get_col(alias, output_field or self.target_field)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 909, in target_field
return self.foreign_related_fields[0]
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 653, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 640, in related_fields
self._related_fields = self.resolve_related_fields()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 625, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model u'user.User' cannot be resolved
Here ConnectedUserPage is a model with schema:
class ConnectedUserPage(TimeStampedModel):
user = models.ForeignKey('user.User', on_delete=models.PROTECT)
page = models.ForeignKey(FacebookPage, on_delete=models.PROTECT)
page_details = jsonb.JSONField()
My versions are :
celery==4.1.1
django-celery-beat==1.1.1
django-celery-results==1.0.1
Django==1.11.13
In case I directly import User model from user app I am getting stuck in circular imports.
Any help would be appreciated, stuck in this loop for a quite while now.
Where's User defined? Is this Django's own user model? If that's the case you can use User model directly:
from django.contrib.auth import get_user_model
User = get_user_model()
class ConnectedUserPage(TimeStampedModel):
user = models.ForeignKey(User, unique=True)
or you can also do
from django.conf import settings
class ConnectedUserPage(TimeStampedModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
If it is your own supplied User model, are you sure user is in INSTALLED_APPS?
Related
I get this error when I try to upgrade my custom module in odoo 13.
Odoo Server Error
Traceback (most recent call last):
File "/odoo/odoo-server/odoo/http.py", line 619, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/odoo/odoo-server/odoo/http.py", line 309, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/odoo/odoo-server/odoo/tools/pycompat.py", line 14, in reraise
raise value
File "/odoo/odoo-server/odoo/http.py", line 664, in dispatch
result = self._call_function(**self.params)
File "/odoo/odoo-server/odoo/http.py", line 345, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/odoo/odoo-server/odoo/service/model.py", line 93, in wrapper
return f(dbname, *args, **kwargs)
File "/odoo/odoo-server/odoo/http.py", line 338, in checked_call
result = self.endpoint(*a, **kw)
File "/odoo/odoo-server/odoo/http.py", line 910, in __call__
return self.method(*args, **kw)
File "/odoo/odoo-server/odoo/http.py", line 510, in response_wrap
response = f(*args, **kw)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 1324, in call_button
action = self._call_kw(model, method, args, kwargs)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 1312, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 387, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 374, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "<decorator-gen-64>", line 2, in button_immediate_upgrade
File "/odoo/odoo-server/odoo/addons/base/models/ir_module.py", line 72, in check_and_log
return method(self, *args, **kwargs)
File "/odoo/odoo-server/odoo/addons/base/models/ir_module.py", line 629, in button_immediate_upgrade
return self._button_immediate_function(type(self).button_upgrade)
File "/odoo/odoo-server/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "/odoo/odoo-server/odoo/modules/registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/odoo/odoo-server/odoo/modules/loading.py", line 471, in load_modules
env['ir.model.data']._process_end(processed_modules)
File "/odoo/odoo-server/odoo/addons/base/models/ir_model.py", line 1971, in _process_end
record.unlink()
File "/odoo/odoo-server/odoo/addons/base/models/ir_model.py", line 1190, in unlink
table=self.env[selection.field_id.model]._table,
File "/opt/odoo/odoo13/odoo/api.py", line 463, in __getitem__
return self.registry[model_name]._browse(self, (), ())
File "/opt/odoo/odoo13/odoo/modules/registry.py", line 177, in __getitem__
return self.models[model_name]
KeyError: 'sales.terms'
This is the sales.terms model
class SalesTermsAndConditions(models.Model):
_name = 'sales.terms'
_description = 'Terms and Conditions'
_rec_name = 'typex'
new_type = fields.Selection([
('accessories', 'Accessories'),
('glass', 'Glass Work'),
('aluminium', 'Aluminium profiles'),
('projects', 'Projects')
], string='Testing')
d_active = fields.Boolean(string='Active')
notes = fields.Text()
I have a new model named 'sales.terms' I created and I created the corresponding ir.model.access.csv file for it, so I traced down the error and discovered that it isn't the whole model giving causing the error but just the selection field, if i remove the selection field the module upgrades fine.
I am confused as to what might be wrong.
I think there is something missing
class SalesTermsAndConditions(models.Model):
_name = 'sales.terms'
_description = 'Terms and Conditions'
_rec_name = 'typex'
new_type = fields.Selection([
('test', 'Test'),
('atest', 'A test'), // Comma is missing
('accessories', 'Accessories'),
('glass', 'Glass Work'),
('aluminium', 'Aluminium profiles'),
('projects', 'Projects')
], string='Testing')
d_active = fields.Boolean(string='Active')
notes = fields.Text()
Try to remove _rec_name.Replace with some field.
_rec_name = "new_type"
The selection seem to be ok. if you rename new_type does it then upgrade?
Can you look first errors wen you boot odoo or reload modules
I'm working on a Django application which fetches JSON data from an API and stores it in PostgreSQL database. But while migrating the app I'm getting these errors:
psycopg2.ProgrammingError: column "data" of relation "WorldBank_projects" does not exist
LINE 1: INSERT INTO "WorldBank_projects" ("data", "project_id", "pro...
What should I change in code to resolve this error?
Here's the traceback:
Traceback (most recent call last):
File "/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column "data" of relation "WorldBank_projects" does not exist
LINE 1: INSERT INTO "WorldBank_projects" ("data", "project_id", "pro...
^
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/python/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/python/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/app/aggregator/WorldBank/management/commands/fetch_wb.py", line 53, in handle
project_abstract = data['project_abstract']
File "/python/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/python/lib/python3.6/site-packages/django/db/models/query.py", line 394, in create
obj.save(force_insert=True, using=self.db)
File "/python/lib/python3.6/site-packages/django/db/models/base.py", line 807, in save
force_update=force_update, update_fields=update_fields)
File "/python/lib/python3.6/site-packages/django/db/models/base.py", line 837, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/python/lib/python3.6/site-packages/django/db/models/base.py", line 923, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/python/lib/python3.6/site-packages/django/db/models/base.py", line 962, in _do_insert
using=using, raw=raw)
File "/python/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/python/lib/python3.6/site-packages/django/db/models/query.py", line 1076, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/python/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1107, in execute_sql
cursor.execute(sql, params)
File "/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 80, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/python/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/python/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column "data" of relation "WorldBank_projects" does not exist
LINE 1: INSERT INTO "WorldBank_projects" ("data", "project_id", "pro...
How to fix this problem?
Here's my code for models.py:
from django.db import models
from django.contrib.postgres.fields import JSONField
class Projects(models.Model):
data = JSONField(null=False)
project_id=models.CharField(max_length=100)
project_name=models.CharField(max_length=100)
status=models.CharField(max_length=10)
country=models.CharField(max_length=100)
locations=JSONField()
mjtheme=models.CharField(max_length=50)
project_docs=JSONField()
source=models.CharField(max_length=10)
mjtheme_namecode=models.CharField(max_length=10)
docty=models.TextField()
countryname=models.CharField(max_length=100)
countrycode=models.CharField(max_length=10)
themecode=models.CharField(max_length=100)
theme_namecode=models.CharField(max_length=100)
project_url=models.TextField()
totalcommamt=models.CharField(max_length=100)
mjthemecode=models.CharField(max_length=100)
sector1=models.CharField(max_length=10)
theme1=models.CharField(max_length=10)
theme2=models.CharField(max_length=10)
theme3=models.CharField(max_length=10)
projectinfo=models.TextField()
country_namecode=models.CharField(max_length=5)
p2a_updated_date=models.CharField(max_length=100)
p2a_flag=models.CharField(max_length=5)
project_abstract=JSONField()
And here's the code for fetch.py file which is stored under /management/commands/fetch.py:
import requests
from django.core.management.base import BaseCommand
from aggregator.WorldBank.models import Projects
class Command(BaseCommand):
def handle(self, **options):
response = requests.get("https://search.worldbank.org/api/v2/projects?format=json&countryshortname_exact=India&source=IBRD&kw=N&rows=7")
data = response.json()
projects = data['projects']
for project in projects:
print(projects[project])
print("\n\n")
data = projects[project]
Projects.objects.create(
project_id = data['id'],
project_name = data['project_name'],
status = data['status'],
country = data['countryshortname'],
locations = data['locations'],
mjtheme = data['mjtheme'],
project_docs = data['projectdocs'],
source = data['source'],
mjtheme_namecode = data['mjtheme_namecode'],
docty = data['docty'],
countryname = data['countryname'],
countrycode = data['countrycode'],
themecode = data['themecode'],
theme_namecode = data['theme_namecode'],
project_url = data['url'],
totalcommamt = data['totalcommamt'],
mjthemecode = data['mjthemecode'],
sector1 = data['sector1'],
theme1 = data['theme1'],
theme2 = data['theme2'],
theme3 = data['theme3'],
projectinfo = data['projectinfo'],
country_namecode = ['country_namecode'],
p2a_updated_date = data['p2a_updated_date'],
p2a_flag = data['p2a_flag'],
project_abstract = data['project_abstract']
)
I'm writing unit tests for my Django REST Framework app and I'm creating my fake testing data using factory_boy. I've come across the following error message when I try to run my tests
File "/Users/thomasheatwole/osf-meetings/meetings/conferences/tests.py", line 69, in setUp
contributor = UserFactory()
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 67, in __call__
return cls.create(**kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 594, in create
return cls._generate(True, attrs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 519, in _generate
obj = cls._prepare(create, **attrs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 494, in _prepare
return cls._create(model_class, *args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/django.py", line 181, in _create
return manager.create(*args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create
obj.save(force_insert=True, using=self.db)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/base.py", line 745, in save_base
update_fields=update_fields, raw=raw, using=using)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 192, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/thomasheatwole/osf-meetings/meetings/submissions/signals.py", line 19, in add_permissions_on_submission_save
submission, submission_contributor, conference_admin, approval)
File "/Users/thomasheatwole/osf-meetings/meetings/submissions/permissions.py", line 167, in set_unapproved_submission_permissions
approval, submission_contributor)
File "/Users/thomasheatwole/osf-meetings/meetings/approvals/permissions.py", line 62, in add_approval_permissions_to_submission_contributor
assign_perm("approvals.delete_approval", submission_contributor, approval)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/shortcuts.py", line 92, in assign_perm
return model.objects.assign_perm(perm, user, obj)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/managers.py", line 43, in assign_perm
obj_perm, created = self.get_or_create(**kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 467, in get_or_create
return self._create_object_from_params(lookup, params)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 499, in _create_object_from_params
obj = self.create(**params)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create
obj.save(force_insert=True, using=self.db)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/models.py", line 39, in save
content_type = ContentType.objects.get_for_model(self.content_object)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 55, in get_for_model
opts = self._get_opts(model, for_concrete_model)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 32, in _get_opts
model = model._meta.concrete_model
AttributeError: 'NoneType' object has no attribute '_meta'
I pretty much have no clue what's going on since my understanding of backend structure isn't great. Here's the factories:
class UserFactory(factory.DjangoModelFactory):
class Meta:
model = User
class ConferenceFactory(factory.DjangoModelFactory):
class Meta:
model = Conference
class ApprovalFactory(factory.DjangoModelFactory):
class Meta:
model = approvalModels.Approval
class SubmissionFactory(factory.DjangoModelFactory):
class Meta:
model = submissionModels.Submission
And here's where I call them:
def setUp(self):
self.user1 = UserFactory(
username = 'Leo',
id = '99'
)
self.user2 = UserFactory(
username = 'LeoLeo'
)
self.conference = ConferenceFactory(
admin = self.user1
)
self.submission1 = SubmissionFactory(
conference = self.conference,
contributor = UserFactory()
)
self.submission2 = SubmissionFactory(
conference = self.conference,
contributor = UserFactory()
)
If you look through the error message, it's specifically complaining about contributor = UserFactory()
Let me know if there's an easy fix, or even some explanation of what's going on would be nice.
Thanks so much!
Here's the file:
tests.py
You need to add correct relations (SubFactory) in the factory definition first.
Please read this part carefully:
http://factoryboy.readthedocs.io/en/latest/recipes.html#copying-fields-to-a-subfactory
In my models.py I have the following model:
from django.contrib.auth.models import User
class Notification(models.Model):
recipient = models.OneToOneField(User)
timestamp = models.DateTimeField()
In views.py, I try to create an instance of this model via Notification.objects.create(recipient = self.request.user, timestamp=timestamp) where self.request.user is an instance of User, and timestamp equals [datetime.datetime(2015, 10, 19, 16, 3, 2, 356585, tzinfo=<UTC>)]. Yet for these values, when the objects.create command is run, I get an error: Type error: expected string or buffer.
The line number happens to be the objects.create command. I suspect my datetime object is misconfigured. The whole trace is as follows:
Internal Server Error: /
Traceback (most recent call last):
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/views/generic/base.py", line 86, in dispatch
return handler(request, *args, **kwargs)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/views/generic/list.py", line 139, in get
context = self.get_context_data(object_list=self.object_list)
File "/home/hassan/Desktop/unconnectedredditpk/links/views.py", line 135, in get_context_data
Unseennotification.objects.create(recipient=self.request.user,timestamp=timestamp)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/manager.py", line 149, in create
return self.get_query_set().create(**kwargs)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/query.py", line 402, in create
obj.save(force_insert=True, using=self.db)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/base.py", line 546, in save
force_update=force_update, update_fields=update_fields)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/base.py", line 650, in save_base
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/manager.py", line 215, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/query.py", line 1661, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 936, in execute_sql
for sql, params in self.as_sql():
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 894, in as_sql
for obj in self.query.objs
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 304, in get_db_prep_save
prepared=False)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 835, in get_db_prep_value
value = self.get_prep_value(value)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 820, in get_prep_value
value = self.to_python(value)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 788, in to_python
parsed = parse_datetime(value)
File "/home/hassan/.virtualenvs/redditpk/local/lib/python2.7/site-packages/django/utils/dateparse.py", line 67, in parse_datetime
match = datetime_re.match(value)
TypeError: expected string or buffer
Stumped about what to do here! I'm using Django 1.5 and Python 2.7.
Timestamp appears to be a list with one datetime in it. It should be a datetime, for example timestamp[0]. It could also be a correctly-formatted string - that's the code path the exception you're seeing comes from, but it fails because the value passed in is a list rather than a string.
This is the error I'm getting:
ERROR 2011-11-19 04:19:55,441 django.py:164] Error encoding AMF request
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/gateway/django.py", line 161, in __call__
logger=self.logger, timezone_offset=timezone_offset)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/__init__.py", line 676, in encode
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/__init__.py", line 520, in _write_body
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/remoting/__init__.py", line 486, in _encode_body
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
func(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf0.py", line 657, in writeAMF3
self.context.getAMF3Encoder(self).writeElement(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
func(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1456, in writeObject
self.writeElement(value)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
func(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1298, in writeList
[self.writeElement(x) for x in n]
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
func(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 358, in __call__
ret = self.func(data, encoder=self.encoder)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 276, in writeDjangoObject
encoder.writeObject(referenced_object)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1468, in writeObject
self.writeElement(value)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
func(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 358, in __call__
ret = self.func(data, encoder=self.encoder)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 276, in writeDjangoObject
encoder.writeObject(referenced_object)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1468, in writeObject
self.writeElement(value)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 499, in writeElement
func(data)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/codec.py", line 358, in __call__
ret = self.func(data, encoder=self.encoder)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 276, in writeDjangoObject
encoder.writeObject(referenced_object)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/amf3.py", line 1447, in writeObject
attrs = alias.getEncodableAttributes(obj, codec=self)
File "/Library/Python/2.6/site-packages/PyAMF-0.6.1-py2.6-macosx-10.6-universal.egg/pyamf/adapters/_django_db_models_base.py", line 173, in getEncodableAttributes
attrs[name] = [x for x in getattr(obj, name).all()]
File "/Users/bryce/Documents/Aptana Studio 3 Workspace/django-blog/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/Users/bryce/Documents/Aptana Studio 3 Workspace/django-blog/django/db/models/query.py", line 774, in _fill_cache
self._result_cache.append(self._iter.next())
File "/Users/bryce/Documents/Aptana Studio 3 Workspace/django-blog/django/db/models/query.py", line 275, in iterator
for row in compiler.results_iter():
File "/Users/bryce/Documents/Aptana Studio 3 Workspace/DennysBE/djangotoolbox/db/basecompiler.py", line 225, in results_iter
self.check_query()
File "/Users/bryce/Documents/Aptana Studio 3 Workspace/DennysBE/djangotoolbox/db/basecompiler.py", line 273, in check_query
raise DatabaseError('This query is not supported by the database.')
DatabaseError: This query is not supported by the database.
Here are my models that matter for this problem:
class ChallengeAct(models.Model):
challenge = models.ForeignKey(Challenge, blank=True, null=True)
user = models.ForeignKey(User, blank=True, null=True)
start_date = models.DateTimeField(blank=True, null=True)
progress_value = models.IntegerField(default=0)
earned_coupon = models.ForeignKey(EarnedCoupon, blank=True, null=True)
Here is the method that causes the error:
def foo_bar(request):
user = request.user
c = ChallengeAct()
c.challenge = Challenge.objects.get(id=1)
c.start_date = datetime.now()
c.progress_value = 1
c.user = user
c.save()
# Here is where I set the user to null to avoid the DatabaseError
c.user = None
return [c]
The interesting thing is that I need to set the c.user = None right before I return it so I don't get the DatabaseError: This query is not supported by the database. problem.
--update-- The more I think about it, it seems like a pyamf and django-nonrel problem with getting the user object. I'm guessing that when pyamf tries to get the user object it is using some type of join query, which isn't supported on django-nonrel.
Why is this? Is there a way around it?
You should not have to to allow for blank=True, null=True for User model. Normally django.contrib.auth.models.AnonymousUser takes care of anonymous requests. It may or may not fix the issue, but it is worth trying, i.e.:
class ChallengeAct(RewardActBase):
user = models.ForeignKey(User)
....