Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query string argument of EXECUTE is null #11

Closed
pajooh opened this issue Mar 15, 2015 · 8 comments
Closed

query string argument of EXECUTE is null #11

pajooh opened this issue Mar 15, 2015 · 8 comments
Assignees
Labels

Comments

@pajooh
Copy link

pajooh commented Mar 15, 2015

i 'm trying save into a partitioned table. the following exception raises:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/lib/python2.7/site-packages/django/db/models/query.py", line 409, in bulk_create
    self._batched_insert(objs_without_pk, fields, batch_size)
  File "/lib/python2.7/site-packages/django/db/models/query.py", line 938, in _batched_insert
    using=self.db)
  File "/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/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 "/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
DataError: query string argument of EXECUTE is null
CONTEXT:  PL/pgSQL function gadget_metadata_insert_child() line 17 at EXECUTE statement

I'm using python 2.7 + django 1.7 + postgresql 9.4
the partition_column is of type DateField, which creates a postgresql date column.
as columntype casting handled properly in date partition function, my use case has nothing special,
I wonder if any one had faced this before?

@maxtepkeev maxtepkeev added the bug label Apr 5, 2015
@maxtepkeev maxtepkeev self-assigned this Apr 5, 2015
@maxtepkeev
Copy link
Owner

I can't reproduce this error with v0.3.0. Please try the new version and if you still get this error, please show me the code of your model. I'm closing this issue for now, but if you still have this error, let me know and I'll reopen it.

@schumannd
Copy link

I encounter the same error:

Internal Server Error: /admin/devices/device/add/
Traceback (most recent call last):
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/contrib/admin/options.py", line 583, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/utils/decorators.py", line 105, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 206, in inner
    return view(request, *args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1453, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/utils/decorators.py", line 29, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/utils/decorators.py", line 105, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/transaction.py", line 394, in inner
    return func(*args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1404, in changeform_view
    self.save_model(request, new_object, form, not add)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1045, in save_model
    obj.save()
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/architect/orms/django/features.py", line 106, in wrapper
    method(instance, *args, **kwargs)
  File "/Users/mac/PycharmProjects/myProject/helpers/model_helpers.py", line 146, in save
    super(AbstractBaseModel, self).save(*args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/models/base.py", line 589, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/mac/.virtualenvs/myEnv/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 "/Users/mac/.virtualenvs/myEnv/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 "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/models/base.py", line 731, in _do_insert
    using=using, raw=raw)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/mac/.virtualenvs/myEnv/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 "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/mac/.virtualenvs/myEnv/lib/python2.7/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
DataError: query string argument of EXECUTE is null
CONTEXT:  PL/pgSQL function devices_device_insert_child() line 14 at EXECUTE statement

I used a fresh DB and one with data. No dice. Using python 2.7.6 django 1.7.3 postgres 9.3.5

Our Model is fairly complex, but basically I only added:

import architect


@architect.install('partition', type='range', subtype='string_firstchars', constraint='2', column='language')
class Device(AbstractBaseModel):
    ...
    language = models.CharField(max_length=8, null=True, blank=True, db_index=True)

and then executed:

architect partition --module devices.models

Any Idea what could be the cause?

@maxtepkeev
Copy link
Owner

@schumannd And you created the table using Django before you added the @architect.install() decorator, right ?

@schumannd
Copy link

No, I tried both. I dropped the database, added the lines, manage.py syncdb from scratch, architect partition...: Same result. Is there any preferred way or order to do it with django?

@maxtepkeev
Copy link
Owner

The order for all ORMs, including Django, is the following:

  1. Define a model
  2. Create the table from this model, e.g. manage.py syncdb or manage.py migrate if you're using migrations (migrations should be created before you run this command of course)
  3. Only after the table has been created, add @architect.install() decorator
  4. Run the architect.partition command

Please be sure to try this order, and if it still doesn't work, I'll try to reproduce the error, I'm reopening issue until we figure out the problem.

Also a few questions:

  1. I see that you're inheriting from AbstractBaseModel can you show the code for it, so I have more chances to reproduce the error
  2. I see that you're using null=True for the language column, what is the logic for that ? I mean you're partitioning your table by language, and what should happen if there is no language ? It should go to the separate partition without translations, right ? Maybe this is the source of a problem, can you try to remove null=True and see if it works, if it does, I'll have to make a fix for this.

@maxtepkeev maxtepkeev reopened this Jul 28, 2015
@schumannd
Copy link

The AbstractBaseModel is not very interesting:

class AbstractBaseModel(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True

    def save(self, *args, **kwargs):
        self.clean()
        super(AbstractBaseModel, self).save(*args, **kwargs)

I'll try without null=True and post results. But for now I will stick to implementing the partitioning manually.

EDIT: It works without the null=True

@maxtepkeev
Copy link
Owner

@schumannd Thanks! I'll try to roll out a fix for this ASAP.

maxtepkeev added a commit that referenced this issue Jul 31, 2015
@maxtepkeev
Copy link
Owner

Fixed in v0.5.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants