I am new to bigdata technologies/hadoop ecosystem.
As part of one of my assignment I am trying to install and run Hue on my single node hadoop cluster [apache distribution hadoop2.6.0].
I have installed hue as per the instructions provided by many websites:
Downloaded latest hue tar file
Unzipped it at one location
Ran sudo make install
It installed hue in /usr/local/hue directory
Updated hue.ini file with required details of my cluster.
When I am trying to access the newly installed hue through web UI using ':8888', it is showing me following error page:
Traceback (most recent call last):
File "/usr/local/hue/desktop/core/src/desktop/lib/wsgiserver.py", line
1198, in communicate
req.respond()
File "/usr/local/hue/desktop/core/src/desktop/lib/wsgiserver.py", line 568,
in respond
self._respond()
File "/usr/local/hue/desktop/core/src/desktop/lib/wsgiserver.py", line 580,
in _respond
response = self.wsgi_app(self.environ, self.start_response)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/core/handlers/wsgi.py",
line 206, in call
response = self.get_response(request)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/core/handlers/base.py",
line 194, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/core/handlers/base.py",
line 236, in handle_uncaught_exception
return callback(request, **param_dict)
File "/usr/local/hue/desktop/core/src/desktop/views.py", line 304, in serve_500_error
return render("500.mako", request, {'traceback': traceback.extract_tb(exc_info[2])})
File "/usr/local/hue/desktop/core/src/desktop/lib/django_util.py", line
225, in render
**kwargs)
File "/usr/local/hue/desktop/core/src/desktop/lib/django_util.py", line
146, in _render_to_response
return django_mako.render_to_response(template, *args, **kwargs)
File "/usr/local/hue/desktop/core/src/desktop/lib/django_mako.py", line
125, in render_to_response
return HttpResponse(render_to_string(template_name, data_dictionary), **kwargs)
File "/usr/local/hue/desktop/core/src/desktop/lib/django_mako.py", line
114, in render_to_string_normal
result = template.render(**data_dict)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Mako-0.8.1-py2.6.egg/mako/template.py",
line 443, in render
return runtime.render(self, self.callable, args, data)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Mako-0.8.1-py2.6.egg/mako/runtime.py",
line 786, in _render
**_kwargs_for_callable(callable_, data))
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Mako-0.8.1-py2.6.egg/mako/runtime.py",
line 818, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Mako-0.8.1-py2.6.egg/mako/runtime.py",
line 844, in _exec_template
callable_(context, *args, **kwargs)
File "/tmp/tmpjqe8jG/desktop/500.mako.py", line 103, in render_body
M_writer(unicode( commonfooter(messages) ))
File "/usr/local/hue/desktop/core/src/desktop/views.py", line 388, in commonfooter
hue_settings = Settings.get_settings()
File "/usr/local/hue/desktop/core/src/desktop/models.py", line 59, in get_settings
settings, created = Settings.objects.get_or_create(id=1)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/manager.py",
line 154, in get_or_create
return self.get_queryset().get_or_create(**kwargs)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/query.py",
line 391, in get_or_create
six.reraise(*exc_info)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/query.py",
line 383, in get_or_create
obj.save(force_insert=True, using=self.db)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/base.py",
line 545, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/base.py",
line 573, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/base.py",
line 654, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/base.py",
line 687, in _do_insert
using=using, raw=raw)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/manager.py",
line 232, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/query.py",
line 1514, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/models/sql/compiler.py",
line 903, in execute_sql
cursor.execute(sql, params)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/utils.py",
line 99, in __exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/usr/local/hue/build/env/lib/python2.6/site-packages/Django-1.6.10-py2.6.egg/django/db/backends/sqlite3/base.py", line 452, in execute
return Database.Cursor.execute(self, query, params)
OperationalError: attempt to write a readonly database
Not sure what does it mean, please help me in resolving this issue
Regards,
Bhupesh
Got it :-)
I was facing this issue because of the hue directory ownership.
I changed the owner of my /usr/local/hue folder :
$ sudo chown -R hue:hue /usr/local/hue
and then tried accessing the URL, it worked. :-)
//Bhupesh
Related
I am trying to use factory boy to generate fake entries but I'm stepping on an issue related with the boolean field.
Follows the Model and ModelFactory:
# models.py
class Record(models.Model):
date_creation = models.DateTimeField()
rec_type = models.CharField(max_length=1, choices=RECORD_TYPES)
direction = models.BooleanField()
# factories.py
class RecordFactory(DjangoModelFactory):
class Meta:
model = Record
date_creation = factory.Faker('date_time')
rec_type = factory.Faker('random_choices', elements=[x[1] for x in Record.RECORD_TYPES])
direction = factory.Faker('pybool')
How do I fix this issue? Seems to be related with the boolean field.
/usr/local/lib/python3.7/site-packages/django/db/models/fields/__init__.py:1427: RuntimeWarning: DateTimeField Record.date_creation received a naive datetime (1
977-11-24 14:21:26) while time zone support is active.
RuntimeWarning)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(1)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 30, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/app/iur/core/management/commands/seed.py", line 60, in handle
self.create(options["records"], RecordFactory)
File "/app/iur/core/management/commands/seed.py", line 47, in create
factory_class.create()
File "/usr/local/lib/python3.7/site-packages/factory/base.py", line 564, in create
return cls._generate(enums.CREATE_STRATEGY, kwargs)
File "/usr/local/lib/python3.7/site-packages/factory/django.py", line 141, in _generate
return super(DjangoModelFactory, cls)._generate(strategy, params)
File "/usr/local/lib/python3.7/site-packages/factory/base.py", line 501, in _generate
return step.build()
File "/usr/local/lib/python3.7/site-packages/factory/builder.py", line 279, in build
kwargs=kwargs,
File "/usr/local/lib/python3.7/site-packages/factory/base.py", line 315, in instantiate
return self.factory._create(model, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/factory/django.py", line 185, in _create
return manager.create(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 422, in create
obj.save(force_insert=True, using=self.db)
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 741, in save
force_update=force_update, update_fields=update_fields)
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 779, in save_base
force_update, using, update_fields,
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 870, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/usr/local/lib/python3.7/site-packages/django/db/models/base.py", line 908, in _do_insert
using=using, raw=raw)
File "/usr/local/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/db/models/query.py", line 1186, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/usr/local/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1335, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(1)
It might not be the boolean field that cause the error but
rec_type = models.CharField(max_length=1, choices=RECORD_TYPES)
As it's max_length is 1. Can you confirm that RECORD_TYPES are max 1 character?
django.db.utils.DataError: value too long for type character varying(1)
This should indicate that it's a VARCHAR of max length 1. And from what I can see from the trace, you're db backend is postgres where there is a native boolean field.
The major issue was that I was using the wrong Faker. This one did what I expected:
# factories.py
...
rec_type = factory.Faker('random_element', elements=[x[0] for x in Record.RECORD_TYPES])
...
Just set e.g. direction = False in RecordFactory. Or, if you want to use faker, you can do direction = Faker().pybool()
I think the error is telling you that your DB backend uses a one letter varchar for representing booleans (most probably "t" and "f").
I'm using django + celery, when running django devserver I'm getting exception
django.db.utils.OperationalError: no such table: main.django_celery_beat_solarschedule__old
and callstack tells that it occured while doing insert into table django_celery_beat_periodictask
Database is sqlite3. Python version is 3.5.6. All migrations were applied and django_celery_beat was added to settings
Calling code:
def register_task(task, interval=DEFAULT_TASK_INTERVAL):
logger.info("Registering periodic task %s with interval %s", task, interval)
name = "Default {}".format(task)
schedule, _ = IntervalSchedule.objects.update_or_create(
every=interval, period=IntervalSchedule.SECONDS)
PeriodicTask.objects.update_or_create(
name=name, defaults={
"interval": schedule,
"task": task
})
Actual traceback:
File "/home/zab/Git/overview-server/overview-server/src/basis/tasks/shedule.py", line 21, in register_task
"task": task
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django_celery_beat/managers.py", line 14, in update_or_create
obj, created = self.get_or_create(defaults=defaults, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 489, in get_or_create
return self._create_object_from_params(lookup, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 521, in _create_object_from_params
obj = self.create(**params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 417, in create
obj.save(force_insert=True, using=self.db)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django_celery_beat/models.py", line 316, in save
super(PeriodicTask, self).save(*args, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/base.py", line 880, in _do_insert
using=using, raw=raw)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1285, in execute_sql
cursor.execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/zab/venv/overview/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 303, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: main.django_celery_beat_solarschedule__old
I suppose you didn't run migrate and as result those tables were not created.
Run
python manage.py migrate
And make sure you added it to INSTALLED_APPS
INSTALLED_APPS = (
...,
'django_celery_beat',
)
The problem was in Django. Migrations were broken for new sqlite.
https://code.djangoproject.com/ticket/29182
Bumping for recent answer. I was using the tables before they were migrated. So I commented out all the code involving beat (except installed apps), ran python manage.py migrate fresh, then uncommented the code
I'm using Django Parler 1.9.2 and Django 2.1.
I have a Business Admin Class with inlines to edit the related models (Service and Resource)
class ServiceInline(TranslatableTabularInline):
model = Service
class ResourceInline(TranslatableTabularInline):
model = Resource
#admin.register(Business)
class BusinessAdmin(TranslatableAdmin):
inlines = [ServiceInline, ResourceInline]
When I try edit a Business in Admin it gives me a IntegrityError:
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/forms/models.py", line 650, in save_existing
return form.save(commit=commit)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/forms/models.py", line 458, in save
self.instance.save()
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/parler/models.py", line 648, in save
self.save_translations(*args, **kwargs)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/parler/models.py", line 701, in save_translations
self.save_translation(translation, *args, **kwargs)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/parler/models.py", line 728, in save_translation
translation.save(*args, **kwargs)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/models/base.py", line 717, in save
force_update=force_update, update_fields=update_fields)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/parler/models.py", line 892, in save_base
super(TranslatedFieldsModelMixin, self).save_base(raw=raw, using=using, **kwargs)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/models/base.py", line 747, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/models/base.py", line 833, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/models/base.py", line 872, in _do_insert
using=using, raw=raw)
File "/home/vagrant/.virtualenvs/appy/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/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/models/query.py", line 1133, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1285, in execute_sql
cursor.execute(sql, params)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/vagrant/.virtualenvs/appy/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "businesses_resource_tran_language_code_master_id_598f5fae_uniq"
DETAIL: Key (language_code, master_id)=(en, 9) already exists.
Any idea in how to solve this?
It's resolved. A was a database trigger. This trigger created a new entry before the execution of save method but after the object being created. I think it's a Django limitation.
I'm working with Django + PostgreSQL and I restored backup from my old DB dump on a current DB due to some reasons. Due to which the sequences of few tables were disturbed and I am not able to create a new Django superuser because of that. Can someone help me with how can I alter sequence of the whole db using any psql command.
Error traceback if I've misinterpreted the error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 63, in execute
return super(Command, self).execute(*args, **options)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 183, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/contrib/auth/models.py", line 168, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/contrib/auth/models.py", line 151, in _create_user
user.save(using=self._db)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 80, in save
super(AbstractBaseUser, self).save(*args, **kwargs)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/base.py", line 824, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/base.py", line 908, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/base.py", line 947, in _do_insert
using=using, raw=raw)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/query.py", line 1045, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1054, in execute_sql
cursor.execute(sql, params)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/orion/workspace/buddy/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "auth_user_pkey"
DETAIL: Key (id)=(1198) already exists.
I want to confirm is this the right way to check for empty queryset, and if it is why am I having a UNIQUE constraint error.
syn_check= Synonym.objects.filter(MD.objects.get(**filter_dict), synonym_type=Stype.objects.filter(description=values.capitalize().strip()), synonym_name=key)
if not syn_check:
print 'unavailable synonym', key, values
syn = Synonym()
syn.synonym_type=Stype.objects.filter(description=values.capitalize().strip()
syn.synonym_name = key.strip()
syn.save()
Am I doing anything that is weird? I also used if not syn_check.count() and I had the same problem.
Here is the traceback :
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/project/PycharmProjects/project/project/management/commands/back_populate_data.py", line 53, in handle
loaded_syn = data_loaded_syn4_pubchem(synonym_decoded, filter_dict)
File "/home/project/PycharmProjects/project/project/lookup_data.py", line 203, in data_loaded_syn4_pubchem
mol_syn_ob.save()
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/base.py", line 589, in save
force_update=force_update, update_fields=update_fields)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/base.py", line 617, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/base.py", line 698, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/base.py", line 731, in _do_insert
using=using, raw=raw)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/query.py", line 921, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 921, in execute_sql
cursor.execute(sql, params)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "/home/project/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: UNIQUE constraint failed: project_synonym.molecule_id, project_synonym.synonym_name, project_synonym.synonym_type_id
Thanks
Checking the queryset as you are doing is fine.
if not syn_check:
However, it is not as efficent as it could be, you are loading all the objects from the database, when all you want to know is whether the queryset is empty or not.
It would be better to use count(),
if not syn_check.count():
and even better to use exists()
if not syn_check.exists():
The problem in your code is where you define the queryset
syn_check = Synonym.objects.filter(MD.objects.get(**filter_dict), synonym_type=Stype.objects.filter(description=values.capitalize().strip()), synonym_name=key)
The filter() method accepts either Q objects as args, or keyword arguments. It doesn't make sense to pass the model instance from MD.objects.get(...) as a positional argument.