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

Modified content of object erased/reverted after calling my_object.save() #60

Open
daniel2013 opened this issue Feb 24, 2012 · 4 comments

Comments

@daniel2013
Copy link

Hi,

I am using te following code to moderate my object:

class NodeModerator(GenericModerator):
    auto_approve_for_superusers = True
    auto_approve_for_staff = True

    visible_until_rejected = False

    visibility_column = 'visible_moderator'

    notify_user = False

    fields_exclude = ['hits', 'author', (and some more fields)] 
moderation.register(Node, NodeModerator)

Then I modify my object and the changes appear in the moderated object admin page.

But when I do:

my_object.author.hits += 1
my_object.author.save()

my_object.hits += 1
my_object.save()

All changes in the moderated object admin disappear/revert back.

Am I doing something wrong or this a bug? And how can I fix it?

Thanks.

@treyhunner
Copy link
Collaborator

This sounds like it might be a bug with the implementation of fields_exclude. Does moderation seem to work as expected when fields_exclude is not present?

@daniel2013
Copy link
Author

When commenting out fields_exclude the following happens:

  • I modify the object's 'desc' field. This change shows up in the moderation admin like it should.
  • Then I visit the object's page which calls n.hits += 1; n.save();
  • Now the moderation admin displays the change for the hit counter but the change for the 'desc' field has disappeared.

@daniel2013
Copy link
Author

Do you think you can fix this bug anytime soon?

@treyhunner
Copy link
Collaborator

I am not currently using django-moderation actively, so I may not look into this soon. Sorry.

I would make sure you are modifying the "unmoderated" object (the unapproved object in the moderation queue) when applying your changes rather than the "moderated" object (the approved object that does not have changes already made to it).
Example 1 (this might be what's happening in your case):

  1. You change object a
  2. You later query for a and change a again in a different way
  3. Your previous changes to a will be overwritten and replaced by the new ones (because you were modifying the already approved version of a instead of the unmoderated version)

Example 2:

  1. You change a
  2. You later query for a and change a.moderated_object.changed_object (this is the latest version of a which may not be moderated yet)
  3. Your initial changes to a and your second changes are both queued for moderation (and are now in a.moderated_object.changed_object)

If you're making your changes through a form, you can use a BaseModeratedObjectForm to make sure you're changing the unmoderated version of the object (read the "Forms" section of the README file).

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

No branches or pull requests

2 participants