title: Python Flask: AttributeError: 'NoneType' object has no attribute 'is_active'
body: <p>Using the <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="noreferrer">Flask Mega Tutorial</a> I'm trying to learn Flask. In <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-vi-profile-page-and-avatars" rel="noreferrer">part 5 of the tutorial</a> I'm now building a profile page which needs the user to be logged in.</p>
  
  <p>Since I'm using the peewee ORM instead of SQLAlchemy, I do adjust the code here and there, but for this case I don't think that matters. I now login using my Google (openID) account and hit an error saying <code>AttributeError: 'NoneType' object has no attribute 'is_active'</code>. The error occurs at the end of this function at the line which says <code>login_user(user, remember = remember_me)</code>.</p>
  
  <pre><code>@oid.after_login
  def after_login(resp):
      if resp.email is None or resp.email == "":
          flash('Invalid login. Please try again.')
          return redirect(url_for('login'))
  
      user = User.select().where(User.email == resp.email).first()
  
      if user is None:
          nickname = resp.nickname
          if nickname is None or nickname == "":
              nickname = resp.email.split('@')[0]
          User(nickname = nickname, email = resp.email, role = models.ROLE_USER, last_seen = datetime.utcnow()).save()
  
      remember_me = False
      if 'remember_me' in session:
          remember_me = session['remember_me']
          session.pop('remember_me', None)
      login_user(user, remember = remember_me)
      return redirect(request.args.get('next') or url_for('index'))
  </code></pre>
  
  <p>Since this piece of code worked before, I wouldn't know why this now gives an error. The <code>is_active</code> method (not attribute) occurs in the User class, which looks like this:</p>
  
  <pre><code>class User(db.Model):
      nickname = CharField()
      email = CharField(max_length=150)
      role = IntegerField(default = ROLE_USER)
      about_me = TextField(null = True, max_length=140)
      last_seen = DateTimeField()
  
      def is_authenticated(self):
          return True
  
      def is_active(self):
          return True
  
      def is_anonymous(self):
          return False
  
      def get_id(self):
          return self.id
  
      def avatar(self, size):
          return 'http://www.gravatar.com/avatar/' + md5(self.email).hexdigest() + '?d=mm&amp;s=' + str(size)
  
      def __repr__(self):
          return '&lt;User %r&gt;' % (self.nickname)
  </code></pre>
  
  <p>But I'm kinda lost as to why this would throw me an error. So my question is really: does anybody know what I' doing wrong here? </p>
  
  <p>Any tips are welcome, since I'm totally lost..</p>