ndarville / pony-forum

A modern alternative to ancient forum CMSes like vBulletin and PHPBB in Python on Django. (Alpha stage.) (NB: dotCloud have since removed their free Sandbox tier.)
http://pony-forum.com
26 stars 7 forks source link

Create dummy objects #52

Closed ndarville closed 11 years ago

ndarville commented 12 years ago

Optional or integrated on deployment?

Has to illustrate:

  1. Different users
  2. Avatars
    • Pagination
    • Save, thank, like, agree
    • Bookmark, save
    • Subscription
    • Lock, close
    • Report, ban
Traceback (most recent call last):
  File "_postinstall/mkplaceholders.py", line 20, in <module>
    title_plain="Discussions", title_html="Discussions")
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/manager.py", line 134, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 449, in get_or_create
    obj.save(force_insert=True, using=self.db)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/base.py", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 1576, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 910, in execute_sql
    cursor.execute(sql, params)
  File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "forum_category_pkey"
DETAIL:  Key (id)=(1) already exists.

Fixed this by reading the docs of get_or_create() and by giving Category’s name field a Unique=True value.


Pre-merge

  1. Works locally
  2. Works online

Post-merge

  1. Works locally
  2. Fails Works online
ndarville commented 12 years ago
  1. Use the dummies to illustrate the aforementioned post and thread states?
  2. Implement a “clear dummy objects” option.
  3. Support for avatars.
ndarville commented 12 years ago

The code now works locally cf. 975df0f4b9, both for the placeholders branch or the merged master. Online, both fail:

19:10:44 [www.0] Traceback (most recent call last):
19:10:44 [www.0]   File "manage.py", line 9, in <module>
19:10:44 [www.0]     execute_from_command_line(sys.argv)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
19:10:44 [www.0]     utility.execute()
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/core/management/__init__.py", line 382, in execute
19:10:44 [www.0]     self.fetch_command(subcommand).run_from_argv(self.argv)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
19:10:44 [www.0]     self.execute(*args, **options.__dict__)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 232, in execute
19:10:44 [www.0]     output = self.handle(*args, **options)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/core/management/base.py", line 371, in handle
19:10:44 [www.0]     return self.handle_noargs(**options)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
19:10:44 [www.0]     cursor = connection.cursor()
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/backends/__init__.py", line 308, in cursor
19:10:44 [www.0]     cursor = util.CursorWrapper(self._cursor(), self)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 177, in _cursor
19:10:44 [www.0]     self.connection = Database.connect(**conn_params)
19:10:44 [www.0]   File "/opt/ve/2.6/lib/python2.6/site-packages/psycopg2/__init__.py", line 179, in connect
19:10:44 [www.0]     connection_factory=connection_factory, async=async)
19:10:44 [www.0] psycopg2.OperationalError: could not connect to server: Connection refused

Split in two:

19:10:44 [www.0]    Is the server running on host "placeholders-xxx.dotcloud.com" and accepting
19:10:44 [www.0]    TCP/IP connections on port 13548?
19:10:44 [www.0] could not connect to server: Connection refused
19:10:44 [www.0]    Is the server running on host "placeholders-xxx.dotcloud.com" and accepting
19:10:44 [www.0]    TCP/IP connections on port 13548?
19:10:44 [www.0] could not connect to server: Connection refused
19:10:44 [www.0]    Is the server running on host "placeholders-xxx.dotcloud.com" and accepting
19:10:44 [www.0]    TCP/IP connections on port 13548?
19:10:44 [www.0] 
19:10:45 [www.0] ERROR: deployment aborted due to unexpected command result: "chmod +x postinstall ; ./postinstall" failed with return code 1
19:10:45 ---> Deploy finished
19:10:45 ---> Failed because of some installation failure
ndarville commented 12 years ago

The problem seems to arise, whenever the terminal connection times out. The timeout occurs completely arbitrarily, but it does not appear to be a problem with the code itself—barring measures that would allow a more generous connection attempt duration.

In other words, the code itself works, but dotCloud is not very tolerant of irregular connections.

ndarville commented 12 years ago

Local

python _postinstall/mkplaceholders.py

Does not work if run as

python _postinstall/mkcategorythreadpost.py
python _postinstall/mkplaceholders.py

Yields:


air:dotcloud-django darville$ python _postinstall/mkcategorythreadpost.py 
air:dotcloud-django darville$ python _postinstall/mkplaceholders.py 
Traceback (most recent call last):
  File "_postinstall/mkplaceholders.py", line 28, in <module>
    title_plain="Discussions", title_html="Discussions")
  File "/Library/Python/2.7/site-packages/django/db/models/manager.py", line 134, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 449, in get_or_create
    obj.save(force_insert=True, using=self.db)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 463, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 551, in save_base
    result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
  File "/Library/Python/2.7/site-packages/django/db/models/manager.py", line 203, in _insert
    return insert_query(self.model, objs, fields, **kwargs)
  File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 1576, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py", line 910, in execute_sql
    cursor.execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/util.py", line 40, in execute
    return self.cursor.execute(sql, params)
  File "/Library/Python/2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute
    return self.cursor.execute(query, args)
django.db.utils.IntegrityError: duplicate key value violates unique constraint "forum_category_pkey"
DETAIL:  Key (id)=(1) already exists.