emmett-framework / emmett

The web framework for inventors
BSD 3-Clause "New" or "Revised" License
1.06k stars 71 forks source link

Bug in join (and including=) #154

Closed josejachuf closed 8 years ago

josejachuf commented 8 years ago

Hi, [weppy 0.7.8]

Using the structure of bloggy app:

users = User.all().join('posts').select() Traceback (most recent call last): File "", line 1, in File "../venv/lib/python3.4/site-packages/weppy/dal/helpers.py", line 471, in select self.db, [], jcolnames[join[1]], compact=False) KeyError: 'posts'

using including: users = User.all().select(including='posts') Traceback (most recent call last): File "", line 1, in File "/lib/python3.4/site-packages/weppy/dal/base.py", line 102, in select self, jdata).select(_fields, *_options) File "/venv/lib/python3.4/site-packages/weppy/dal/helpers.py", line 523, in select self.db, [], jcolnames[join[1]], compact=False) KeyError: 'posts

Jose

gi0baro commented 8 years ago

@josejachuf I'm gonna inspect this asap.

gi0baro commented 8 years ago

@josejachuf can you give more details about what you have stored inside the db? Tested with a fresh bloggy app (run setup, so just the admin user and no posts):

Python 3.5.1 (default, Feb 20 2016, 16:05:46)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
weppy 0.8-dev shell on app: bloggy
>>> User.all().count()
1
>>> Post.all().count()
0
>>> users = User.all().join('posts').select()
>>> users
<Rows (0)>
>>> users = User.all().select(including='posts')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/giovanni/Development/Weppy/weppy/weppy/dal/base.py", line 102, in select
    self, jdata).select(*fields, **options)
  File "/Users/giovanni/Development/Weppy/weppy/weppy/dal/helpers.py", line 523, in select
    self.db, [], jcolnames[join[1]], compact=False)
KeyError: 'posts'

As you can see I can reproduce the including error but not the join one.

josejachuf commented 8 years ago

Hi @gi0baro I have a user and several post

gi0baro commented 8 years ago

@josejachuf ok, you're right, I created a post and now I can reproduce both the errors. Will work on these asap.

josejachuf commented 8 years ago

@gi0baro print(jcolnames) {'"posts"': ['"id"', '"title"', '"text"', '"date"', '"user"'], '"users"': ['"id"', '"created_at"', '"updated_at"', '"email"', '"password"', '"registration_key"', '"reset_password_key"', '"registration_id"', '"first_name"', '"last_name"']}

why the double quote? '"posts"' (' and ")

gi0baro commented 8 years ago

@josejachuf this is published on 0.7.9