r4fek / django-cassandra-engine

Django Cassandra Engine - the Cassandra backend for Django
BSD 2-Clause "Simplified" License
365 stars 85 forks source link

post_save signal not working (Django 1.7) #4

Closed muminoff closed 9 years ago

muminoff commented 9 years ago

I have tried to implement post_save signal, but failed.

Here is my simple code:

from cqlengine import columns
from cqlengine.models import Model
from uuid import uuid1
from django.db.models.signals import post_save

class Post(Model):
    __table_name__ = 'published_posts'
    post_id = columns.TimeUUID(primary_key=True, default=uuid1)   
    title = columns.Text()
    content = columns.Text()

def elasticsearch_index_task(sender, instance, created, **kwargs):
    print "Executed.."

post_save(elasticsearch_index_task, sender=Post)

This works:

from cqlengine import columns
from cqlengine.models import Model
from uuid import uuid1
from django.db.models.signals import post_save

class Post(Model):
    __table_name__ = 'published_posts'
    post_id = columns.TimeUUID(primary_key=True, default=uuid1)   
    title = columns.Text()
    content = columns.Text()

    def save(self, *args, **kwargs):
        print "Executed.."
        super(Post, self).save(*args, **kwargs)

Last code works but I needed post_save not pre_save.

r4fek commented 9 years ago

Take a look at https://github.com/cqlengine/cqlengine/issues/195. This is purely related to cqlengine. Django-cassandra-engine is just a database wrapper, so you should probably address issues like this in cqlengine project.

zleroy commented 9 years ago

I also am not able to use post_save with MySQL backend. This block of code works fine in Django 1.6.10 but is broken in 1.7.3:

import logging

from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver

log = logging.getLogger(__name__)

class UserProfile(models.Model):
    uuid = models.CharField(max_length=36)
    user = models.OneToOneField(User)

@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
    """
    When a new user is created, add a UserProfile
    """
    log.debug('received post save signal: {}'.format(instance))
    if created:
        UserProfile.objects.create(user=instance)
r4fek commented 9 years ago

You're saing that with mysql as primary backend and django_cassandra_engine as secondary post_save signal does not work? Does it work if you remove django_cassandra_engine from settings?