Skip to content

M2M and all_columns #728

@powellnorma

Description

@powellnorma

When using all_columns() in a M2M Select like this:

from piccolo.columns.column_types import Varchar, LazyTableReference, ForeignKey
from piccolo.columns.m2m import M2M
from piccolo.engine.postgres import PostgresEngine
from piccolo.table import Table
from starlette.applications import Starlette
import uvicorn

DB = PostgresEngine(config={
    'host': 'localhost',
    'database': 'test',
    'user': 'test',
    'password': ''
})

class Band(Table):
    name = Varchar()
    genres = M2M(LazyTableReference("GenreToBand", module_path=__name__))

class Genre(Table):
    name = Varchar()
    bands = M2M(LazyTableReference("GenreToBand", module_path=__name__))

# This is our joining table:
class GenreToBand(Table):
    band = ForeignKey(Band)
    genre = ForeignKey(Genre)

async def on_startup():
    await Band.select(Band.name, Band.genres(Genre.all_columns(), as_list=True))

app = Starlette(debug=True, on_startup=[on_startup])

if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=64215)

I get:

  [..]
  File "/piccolo/piccolo/columns/m2m.py", line 53, in <genexpr>
    (column.__class__.value_type in safe_types)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'list' has no attribute 'value_type'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions