Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An encode error occur in Chapter11.3.1 if user.email is Null. #54

Closed
zhujinhe opened this issue Jun 18, 2015 · 6 comments
Closed

An encode error occur in Chapter11.3.1 if user.email is Null. #54

zhujinhe opened this issue Jun 18, 2015 · 6 comments
Labels

Comments

@zhujinhe
Copy link

After execute command Post.generate_fake(100)in the chapter 11.3.1, an encode error occur like below:

  File "/flask/app/templates/base.html", line 62, in block "content"
    {% block page_content %}{% endblock %}
  File "/flask/app/templates/index.html", line 15, in block "page_content"
    {% include '_posts.html' %}
  File "/flask/app/templates/_posts.html", line 6, in top-level template code
    <img class="img-rounded profile-thumbnail" src="{{ post.author.gravatar(size=40) }}">
  File "/flask/app/models.py", line 183, in gravatar
    self.email.encode('utf-8')).hexdigest()
AttributeError: 'NoneType' object has no attribute 'encode'

After the git checkout 11c, there is no column named 'user.email' in data-dev.sqlite.
After executing the python manage.py db upgrade command, 'user.email' field of exiting data should be filled with Null, and this will cause an error on line self.email.encode('utf-8')).hexdigest() when generating the Gravatar URL.

What should we do about this issue, set user.email NOT NULL or just do some extra check on gravatar() of app/models.py?

@lambdaplus
Copy link

How to fix it ???

@miguelgrinberg
Copy link
Owner

The email field of the users table was added back in chapter 8. If for some reason you ended up with a database that has users that don't have an email, you can manually add those missing emails, or if you don't have any information in your database that you need to keep, just start over with a new database.

It also does not hurt to add a check for user.email is not None before generating the avatar, but during normal use, it would never be possible for a user to register without having an email address.

@lambdaplus
Copy link

Thanks, I have fixed it.
In the data-dev.sqlite, there is two id no email, when i use sqlitebrowser add them, the program work well

@miguelgrinberg
Copy link
Owner

@lambdaplus Note that you shouldn't be using data-test.sqlite, that is the database used by unit tests.

@lambdaplus
Copy link

oh oh oh, it should be the data-dev.sqlite.
I write it wrong.

@lambdaplus
Copy link

I have updated my comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants