piccolo-orm / piccolo

A fast, user friendly ORM and query builder which supports asyncio.
https://piccolo-orm.com/
MIT License
1.45k stars 91 forks source link

Add columns with `secret=True` parameter to `Table._meta.secret_columns` #918

Open patrickneise opened 10 months ago

patrickneise commented 10 months ago

In working with PydanticDTO from litestar, realized that columns with secret=True parameter were not being added to Table._meta.secret_columns

Seems like a relatively small change:

# piccolo/table.py

# line 85 -> update type from Secret to Column to support any Column type as secret_column
secret_columns: t.List[Column] = field(default_factory=list)

# line 271 -> update type from Secret to Column any Column type as secret_column
secret_columns: t.List[Column] = []

# line 311 -> add check for secret param
if isinstance(column, Secret) or column._meta.secret:
    secret_columns.append(column)

With new test:

# tests/table/test_metaclass.py
def test_secret_columns_with_param(self):
    """
    Make sure TableMeta.secret_columns include columns with `secret=True`
    """

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

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

Changes staged for PR here.

dantownsend commented 10 months ago

Sorry for the slow response on this. I was mulling over what to do.

I think your changes makes perfect sense - if you can open a PR, I'll merge it in. Thanks!