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

don't mask parent table on single-table inheritance #561

Merged
merged 1 commit into from
Oct 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ Changelog
=========


Version 2.3.2
-------------

Released on October 11, 2017

- Don't mask the parent table for single-table inheritance models. (`#561`_)

.. _#561: https://github.com/mitsuhiko/flask-sqlalchemy/pull/561


Version 2.3.1
-------------

Expand Down
2 changes: 1 addition & 1 deletion flask_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ._compat import itervalues, string_types, to_str, xrange
from .model import DefaultMeta

__version__ = '2.3.1'
__version__ = '2.3.2'

# the best timer function for the platform
if sys.platform == 'win32':
Expand Down
9 changes: 9 additions & 0 deletions flask_sqlalchemy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def __init__(cls, name, bases, d):

super(NameMetaMixin, cls).__init__(name, bases, d)

# __table_cls__ has run at this point
# if no table was created, use the parent table
if (
'__tablename__' not in cls.__dict__
and '__table__' in cls.__dict__
and cls.__dict__['__table__'] is None
):
del cls.__table__

def __table_cls__(cls, *args, **kwargs):
"""This is called by SQLAlchemy during mapper setup. It determines the
final table object that the model will use.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='Flask-SQLAlchemy',
version='2.3.1',
version='2.3.2',
url='http://github.com/mitsuhiko/flask-sqlalchemy',
license='BSD',
author='Armin Ronacher',
Expand Down
11 changes: 11 additions & 0 deletions tests/test_table_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,14 @@ class User(db.Model):
pass

assert 'could not assemble any primary key' in str(info.value)


def test_single_has_parent_table(db):
class Duck(db.Model):
id = db.Column(db.Integer, primary_key=True)

class Call(Duck):
pass

assert Call.__table__ is Duck.__table__
assert '__table__' not in Call.__dict__