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

Fixes #554 representation of new model instances #555

Merged
merged 4 commits into from Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion flask_sqlalchemy/model.py
Expand Up @@ -118,5 +118,9 @@ class Model(object):
query = None

def __repr__(self):
pk = ', '.join(to_str(value) for value in inspect(self).identity)
identity = inspect(self).identity
if identity is None:
pk = "(transient {0})".format(id(self))
else:
pk = ', '.join(to_str(value) for value in identity)
return '<{0} {1}>'.format(type(self).__name__, pk)
1 change: 1 addition & 0 deletions tests/test_model_class.py
Expand Up @@ -43,6 +43,7 @@ class Report(db.Model):
db.create_all()

u = User(name='test')
assert repr(u).startswith("<User (transient ")
db.session.add(u)
db.session.flush()
assert repr(u) == '<User test>'
Expand Down