Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pylons 1.0 AttributeError: 'module' object has no attribute 'metadata'

Python noob trying to learn Pylons. I'm using the QuickWiki tutorial (http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/) from the 1.0 documentation, but this alleged "1.0" doc seems to just be "0.9.7"; I suspect that this has something to do with the error I'm getting.

When I execute "paster setup-app development.ini", I get this:

(mydevenv)lucid@lucid-laptop:~/QuickWiki$ paster setup-app development.ini
Traceback (most recent call last):
... edited for brevity...
File "/home/lucid/mydevenv/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg/pkg_resources.py", line 1954, in load
File "/home/lucid/QuickWiki/quickwiki/config/middleware.py", line 11, in <module>
from quickwiki.config.environment import load_environment
File "/home/lucid/QuickWiki/quickwiki/config/environment.py", line 12, in <module>
from quickwiki.model import init_model
File "/home/lucid/QuickWiki/quickwiki/model/__init__.py", line 27, in <module>
pages_table = sa.Table('pages', meta.metadata,
AttributeError: 'module' object has no attribute 'metadata'
(mydevenv)lucid@lucid-laptop:~/QuickWiki$
like image 901
shiki Avatar asked Jul 04 '26 13:07

shiki


2 Answers

This is mistake in documentation http://pylonshq.com/docs/en/1.0/tutorials/quickwiki_tutorial/

Declare pages_table like this

from quickwiki.model.meta import Base
pages_table = sa.Table('pages', Base.metadata,
                sa.Column('title', sa.types.Unicode(40), primary_key=True),
                sa.Column('content', sa.types.UnicodeText(), default='')
                )

No loger meta.metadata, use meta.Base.metadata and define you models using SqlAlchemy declarative base extension http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table-class-and-mapper-all-at-once-declaratively

like image 50
estin Avatar answered Jul 06 '26 01:07

estin


Your comment on estin answer asks whether this changes between SqlAlchemy 0.5 and 0.6.

It does not. It's the same. It is Pylons which have different defaults now. As estin says Pylons defaults to creating a declarative_base() so that you can use SqlAlchemy declaratively.

class MyRecord(Base):
     __tablename__ = "myrecord"

     id = Column(Integer, primary_key=True)
     data = Column(Unicode, nullable=False)

This is instead of specifying first the tables using Table() constructs, then creating your classes and then using mapper() to map them together.

SqlAlchemy Declarative does this automatically. Quickwiki tells you to use the explicit non-declarative version of SqlAlchemy which is there are no reason for (declarative is more concise). Pylons used to expose the default metadata as model.meta.metadata but now it is created by declarative_base() and exposed in model.meta.Base.metadata.

like image 26
driax Avatar answered Jul 06 '26 02:07

driax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!