Opened 12 years ago

Closed 12 years ago

#19068 closed Bug (duplicate)

comments in a multiple database context

Reported by: Eric Simorre Owned by: nobody
Component: contrib.comments Version:
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

a legacy database, another database to store (django.contrib.admin.)comments: it does not work.

Change History (8)

comment:1 by Eric Simorre, 12 years ago

I would suggest to replace _base_manager.using(self._state.db) by objects below

  • contenttypes.models.py:
        def get_object_for_this_type(self, **kwargs):
            """
            Returns an object of this type for the keyword arguments given.
            Basically, this is a proxy around this object_type's get_object() model
            method. The ObjectNotExist exception, if thrown, will not be caught,
            so code that calls this method should catch it.
            """
            return self.model_class()._base_manager.using(self._state.db).get(**kwargs)
    

idem for _default_manager.using(self.target_object._state.db) below

  • comments.forms.py:
        def check_for_duplicate_comment(self, new):
            """
            Check that a submitted comment isn't a duplicate. This might be caused
            by someone posting a comment twice. If it is a dup, silently return the *previous* comment.
            """
            possible_duplicates = self.get_comment_model()._default_manager.using(
                self.target_object._state.db
            ).filter(
                content_type = new.content_type,
                object_pk = new.object_pk,
                user_name = new.user_name,
                user_email = new.user_email,
                user_url = new.user_url,
            )
            for old in possible_duplicates:
                if old.submit_date.date() == new.submit_date.date() and old.comment == new.comment:
                    return old
    
            return new
    

comment:2 by Stephen Burrows, 12 years ago

Resolution: needsinfo
Status: newclosed

I wouldn't be surprised if contrib.comments had issues related to multiple databases. But neither of the changes suggested would improve multiple database support. _default_manager, for example, is usually the same as .objects, unless a new default manager is being used (in which case that should probably be used instead of .objects).

It would be great if you could gather more information and reopen this ticket. What's the exact problem you're seeing? Are you getting any kind of traceback?

comment:3 by Eric Simorre, 12 years ago

my contenttypes' table is in sqlitedb , self.model_class() is stored in oracledb

this expression is incorrect because "self" is a ContentType object
self.model_class()._base_manager.using(self._state.db).get(**kwargs)

The commented object (oracledb) is searched in the contenttype sqlitedb. If "objects" is used, the db is right.

I have no trace (the project is deployed in an intranet), but the error message is: table xxx not found.

comment:4 by Eric Simorre, 12 years ago

Resolution: needsinfo
Status: closedreopened

comment:5 by Eric Simorre, 12 years ago

It is obvious that the line code below raise a "table xxx not found" exception if ContentType and the target model are stored in 2 distincts db

class ContentType:
    ...
        return self.model_class()._base_manager.using(self._state.db).get(**kwargs)

Same thing below if the Comment model and the target model are stored in 2 distincts db

class CommentDetailsForm:
    ...
        possible_duplicates = self.get_comment_model()._default_manager.using(
            self.target_object._state.db
        )....

By using the default manager "objects", the bug is fixed. I confirm that it works.

It's very interesting, you can comment objects stored in a legacy database without storing extra data inside.

comment:6 by Preston Holmes, 12 years ago

Is this not really a duplicate of #15610?

in reply to:  6 comment:7 by Eric Simorre, 12 years ago

not exactly because the target component is contrib.comment; but both should be analysed together.

comment:8 by Preston Holmes, 12 years ago

Resolution: duplicate
Status: reopenedclosed

solve #15610 / #16039 and this is solved

comments is just a specific case of the general problem

Note: See TracTickets for help on using tickets.
Back to Top