Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

SQLQueryTriggered disrupts some template tags because of the non-determinism #281

Closed
duilio opened this Issue · 1 comment

2 participants

@duilio

I just ran into an issue with the debug toolbar. I'm using django.contrib.comments and I've noticed that since I've enabled the toolbar all the first comments of the items were from anonymous users, even if the user was actually set. It turned out to be a strange issue because of the SQLQueryTriggered mechanic. django.contrib.comments has the following code to handle usernames:

    def _get_userinfo(self):
        """
        Get a dictionary that pulls together information about the poster
        safely for both authenticated and non-authenticated comments.

        This dict will have ``name``, ``email``, and ``url`` fields.
        """
        if not hasattr(self, "_userinfo"):
            self._userinfo = {
                "name"  : self.user_name,
                "email" : self.user_email,
                "url"   : self.user_url
            }
            if self.user_id:
                u = self.user
                if u.email:
                    self._userinfo["email"] = u.email

                # If the user has a full name, use that for the user name.
                # However, a given user_name overrides the raw user.username,
                # so only use that if this comment has no associated name.
                if u.get_full_name():
                    self._userinfo["name"] = self.user.get_full_name()
                elif not self.user_name:
                    self._userinfo["name"] = u.username
        return self._userinfo

The error comes up because of the non-determinism introduced by the debug toolbar: first a _userinfo attribute is created with some defaults then it checks for the username details and it changes it. The first time the second part is ran debug toolbar raises a SQLQueryTriggered exception (I guess for sql tracking) and it cannot finish to fill the _userinfo attribute, the second time it is called the result is obviously partial.

@aaugustin
Owner

I'm going to close this ticket because django.contrib.comments is deprecated and there's no actionable idea to improve the situation. Sorry.

@aaugustin aaugustin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.