Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions piccolo/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TableMeta:
foreign_key_columns: list[ForeignKey] = field(default_factory=list)
primary_key: Column = field(default_factory=Column)
json_columns: list[Union[JSON, JSONB]] = field(default_factory=list)
secret_columns: list[Secret] = field(default_factory=list)
secret_columns: list[Column] = field(default_factory=list)
auto_update_columns: list[Column] = field(default_factory=list)
tags: list[str] = field(default_factory=list)
help_text: Optional[str] = None
Expand Down Expand Up @@ -274,7 +274,7 @@ def __init_subclass__(
non_default_columns: list[Column] = []
array_columns: list[Array] = []
foreign_key_columns: list[ForeignKey] = []
secret_columns: list[Secret] = []
secret_columns: list[Column] = []
json_columns: list[Union[JSON, JSONB]] = []
email_columns: list[Email] = []
auto_update_columns: list[Column] = []
Expand Down Expand Up @@ -315,7 +315,7 @@ def __init_subclass__(
if isinstance(column, Email):
email_columns.append(column)

if isinstance(column, Secret):
if isinstance(column, Secret) or column._meta.secret:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to check isinstance(column, Secret) - just column._meta.secret alone should work, because Secret columns should have column._meta.secret = True.

secret_columns.append(column)

if isinstance(column, ForeignKey):
Expand Down
13 changes: 13 additions & 0 deletions tests/table/test_metaclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ class Classified(Table):
Classified._meta.secret_columns, [Classified.top_secret]
)

def test_secret_columns_with_argument(self):
"""
Make sure TableMeta.secret_columns are setup correctly
with ``secret=True`` argument.
"""

class Classified(Table):
top_secret = Varchar(secret=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a sanity check, add a non-secret column here too, to make sure only secret columns are added to _meta.secret_columns. For example:

class Classified(Table):
    top_secret = Varchar(secret=True)
    public = Varchar()

You might also consider merging this test with the above test, so we have this:

def test_secret_columns(self):
    """
    Make sure ``TableMeta.secret_columns`` are setup correctly.
    """

    class Classified(Table):
        top_secret = Secret()
        confidential = Varchar(secret=True)
        public = Varchar()

    self.assertEqual(
        Classified._meta.secret_columns,
        [Classified.top_secret, Classified.confidential]
    )


self.assertEqual(
Classified._meta.secret_columns, [Classified.top_secret]
)

def test_json_columns(self):
"""
Make sure TableMeta.json_columns are setup correctly.
Expand Down