Trying to get property of non-object in wp-includes/capabilities.php

You probably already figured this out, but I just had this issue and figured it out. Hopefully, if anyone runs into this problem, this may help.

My problem came from the Disqus Comment System plugin. Because I had used my Disqus user name to do some test comments on a dev site, when I linked my production site to the dev site, it created comments on test blog posts that didn’t exist.

I had to go into the database and delete the comment rows that were attached to nonexistent post IDs, which fixed the problem for me.