Opened 4 years ago

Closed 4 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


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

Change History (8)

comment:1 Changed 4 years ago by Eric Simorre

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

        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

        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(
                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 == and old.comment == new.comment:
                    return old
            return new

comment:2 Changed 4 years ago by Stephen Burrows

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 Changed 4 years ago by Eric Simorre

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

this expression is incorrect because "self" is a ContentType object

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 Changed 4 years ago by Eric Simorre

Resolution: needsinfo
Status: closedreopened

comment:5 Changed 4 years ago by Eric Simorre

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(

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 Changed 4 years ago by Preston Holmes

Is this not really a duplicate of #15610?

comment:7 in reply to:  6 Changed 4 years ago by Eric Simorre

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

comment:8 Changed 4 years ago by Preston Holmes

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