Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a clean error when inserting objects in a table without primary key #37

Open
k4nar opened this issue Jan 30, 2018 · 0 comments
Open
Labels

Comments

@k4nar
Copy link
Contributor

k4nar commented Jan 30, 2018

If we try to insert value in a table which doesn't have a pk, we get the following error:

(pystache) perette@bobbynette:~/git/populous/demo_superette$ populous run postgres blueprints/*.yml
Getting existing unique values...
Starting generation...
Traceback (most recent call last):
 File "/home/perette/.virtualenvs/pystache/bin/populous", line 11, in <module>
   sys.exit(cli())
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
   return self.main(*args, **kwargs)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/click/core.py", line 697, in main
   rv = self.invoke(ctx)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
   return _process_result(sub_ctx.command.invoke(sub_ctx))
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
   return _process_result(sub_ctx.command.invoke(sub_ctx))
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
   return ctx.invoke(self.callback, **ctx.params)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
   return callback(*args, **kwargs)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/cli.py", line 75, in postgres
   db=db, user=user, password=password)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/cli.py", line 53, in _generic_run
   blueprint.generate()
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/blueprint.py", line 143, in generate
   buffer.flush()
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/buffer.py", line 23, in flush
   self.write(self.blueprint.items[item_name], buffer)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/buffer.py", line 30, in write
   item, tuple(item.db_values(obj) for obj in buffer)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/backends/postgres.py", line 76, in write
   self.get_pk_column(item.table)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/functools32/functools32.py", line 400, in wrapper
   result = user_function(*args, **kwds)
 File "/home/perette/.virtualenvs/pystache/local/lib/python2.7/site-packages/populous/backends/postgres.py", line 140, in get_pk_column
   return cursor.fetchone()[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

We should return a descriptive error instead.

@k4nar k4nar added the bug label Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant