function() takes 1 positional argument but 2 were given - python

I'm trying to clone this Django repo and run it on my local machine, but I've run into the classic function() takes 1 positional argument but 2 were given error.
After cloning the repo I created a virtual environment and installed all the dependencies,
But when I run
py manage.py migrate
I get the above-mentioned error.
What's confusing me is that the error is occurring in a python file automatically generated in the virtual environment and according to other questions on SO about this, the code seems correct.
Here's the trace
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django_prometheus\apps.py", line 22, in ready
ExportMigrations()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django_prometheus\migrations.py", line 39, in ExportMigrations
executor = MigrationExecutor(connections[alias])
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\migrations\loader.py", line 53, in __init__
self.build_graph()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\migrations\loader.py", line 220, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
if self.has_table():
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\migrations\recorder.py", line 55, in has_table
with self.connection.cursor() as cursor:
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
self.ensure_connection()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
self.connect()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 202, in connect
self.init_connection_state()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\mysql\base.py", line 245, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\mysql\features.py", line 150, in is_sql_auto_is_null_enabled
return self.connection.mysql_server_data['sql_auto_is_null']
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\mysql\base.py", line 366, in mysql_server_data
with self.temporary_connection() as cursor:
File "C:\Python\lib\contextlib.py", line 113, in __enter__
return next(self.gen)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 603, in temporary_connection
with self.cursor() as cursor:
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\utils\asyncio.py", line 26, in inner
return func(*args, **kwargs)
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
return self._cursor()
File "C:\Users\lenovo\Desktop\dev\work\django-sspanel\sspanel_env\lib\site-packages\django\db\backends\base\base.py", line 237, in _cursor
return self._prepare_cursor(self.create_cursor(name))
TypeError: create_cursor() takes 1 positional argument but 2 were given
Base.py in the virtual environment.
def _cursor(self, name=None):
self.ensure_connection()
with self.wrap_database_errors:
return self._prepare_cursor(self.create_cursor(name))
def create_cursor(self, name=None):
"""Create a cursor. Assume that a connection is established."""
raise NotImplementedError('subclasses of BaseDatabaseWrapper may require a create_cursor() method')
I was hoping that someone could try cloning the repo and running it locally to see whether they could recreate the problem or maybe help me understand what's causing it.

Related

How can I solve my connection error in mysql

I've tried to connect my db. All db settings in settings.py is checked and they are correct. When I run the server, I face an error which is shown below. I searched at internet and I find solutions but all them is working for lower python version. I am using the newest python version. My error is that:
System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
self.check_migrations()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/base.py", line 453, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/loader.py", line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
if self.has_table():
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/migrations/recorder.py", line 56, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/base/base.py", line 197, in connect
self.init_connection_state()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 231, in init_connection_state
if self.features.is_sql_auto_is_null_enabled:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/features.py", line 82, in is_sql_auto_is_null_enabled
cursor.execute('SELECT ##SQL_AUTO_IS_NULL')
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/utils.py", line 103, in execute
sql = self.db.ops.last_executed_query(self.cursor, sql, params)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
This is an old issue about previous versions of django. It is currently 3.1.2 and the code block which causes the problem was fixed.
https://github.com/django/django/blob/master/django/db/backends/mysql/operations.py
You may try pip install -U django if your django version is newer then 3.0.0 (good)
Other choices are changing your django versions source code at related line in your virtualenv (ugly), or monkey patch the related function (bad)

can't run my server because of mysql errors

I am doing a project in django and when i run my server python manage.py runserver i get the following errors.
Performing system checks...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x1045406a8>
Traceback (most recent call last):
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 236, in get_new_connection
return Database.connect(**conn_params)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (61)")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
self.check(display_num_errors=True)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
include_deployment_checks=include_deployment_checks,
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/core/checks/model_checks.py", line 27, in check_all_models
errors.extend(model.check(**kwargs))
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/models/base.py", line 1200, in check
errors.extend(cls._check_fields(**kwargs))
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/models/base.py", line 1272, in _check_fields
errors.extend(field.check(**kwargs))
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 894, in check
errors = super().check(**kwargs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 206, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 303, in _check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/validation.py", line 21, in check_field
field_type = field.db_type(self.connection)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 648, in db_type
return connection.data_types[self.get_internal_type()] % data
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 133, in data_types
if self.features.supports_microsecond_precision:
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/mysql/features.py", line 65, in supports_microsecond_precision
return self.connection.mysql_version >= (5, 6, 4)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 345, in mysql_version
with self.temporary_connection() as cursor:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 576, in temporary_connection
cursor = self.cursor()
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
return self._cursor()
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
self.ensure_connection()
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 236, in get_new_connection
return Database.connect(**conn_params)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/Users/x/Desktop/bakeinsta/env/lib/python3.6/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' (61)")

Django: detect module level db queries

Database queries at modul level (aka import-time) can make trouble in django.
See: https://groups.google.com/forum/#!topic/django-developers/7JwWatLfP44/discussion
Trouble:
The real db gets accessed in tests, not the test-database.
Monkey patching in app-ready signals are too late
...
How can I detect the particular python source line which accesses my database before the app ready signal happens?
I found a solution. It's "dirty", but works.
If you add assert 0 to get_new_connection of django/db/backends/postgresql/base.py
Then you see a very long traceback. It reveals where you do access the database too early.
Of course you should only do this in your development environment.
I guess roughly the same should work for sqlite.
foobar_vums_d#aptguettler:~$ py.test -k ...
Traceback (most recent call last):
File "/home/foobar_vums_d/bin/py.test", line 11, in <module>
sys.exit(main())
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/_pytest/config.py", line 49, in main
return config.hook.pytest_cmdline_main(config=config)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
_MultiCall(methods, kwargs, hook.spec_opts).execute()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
res = hook_impl.function(*args)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/pytest_djangotools/hooks.py", line 46, in pytest_cmdline_main
import consolescript_django
File "/home/foobar_vums_d/src/djangotools/consolescript_django/__init__.py", line 11, in <module>
django.setup()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/foobar_vums_d/src/djangotools/djangotools/apps.py", line 19, in ready
url_patterns = get_resolver(None).url_patterns
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/foobar_vums_d/src/foobar-vums/foobar_vums/etc/rooturls.py", line 11, in <module>
urlpatterns = collect_urlpatterns_from_apps()
File "/home/foobar_vums_d/src/djangotools/djangotools/utils/urlresolverutils.py", line 124, in collect_urlpatterns_from_apps
urls_module = importlib.import_module(app_import_string + '.urls')
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/foobar_vums_d/src/foobar/foobar/urls.py", line 310, in <module>
urlpatterns.append(url(r'^', include(collect_urlpatterns_from_package(views))))
File "/home/foobar_vums_d/src/djangotools/djangotools/utils/urlresolverutils.py", line 94, in collect_urlpatterns_from_package
import_package(views_package)
File "/home/foobar_vums_d/src/djangotools/djangotools/utils/urlresolverutils.py", line 89, in import_package
importlib.import_module(module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/foobar_vums_d/src/foobar/foobar/views/issue/legacy_edit2.py", line 55, in <module>
for index in Index.objects.all():
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/models/query.py", line 258, in __iter__
self._fetch_all()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/models/query.py", line 1074, in _fetch_all
self._result_cache = list(self.iterator())
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/models/query.py", line 52, in __iter__
results = compiler.execute_sql()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 846, in execute_sql
cursor = self.connection.cursor()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/home/foobar_vums_d/local/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 105, in connect
assert 0
AssertionError
In this case the buggy line is in src/foobar/foobar/views/issue/legacy_edit2.py
You find this by going the stack from bottom to top, skipping all lines containing /site-packages/django/.

Why does pyramid give exception of zipimporter.get_filename()

I am writing a simple pyramid application, and I try to run it pserve development.ini.
I got this:
Traceback (most recent call last):
File "/apps/my/python/packages/.mytest/current/bin/pserve", line 5, in <module>
sys.exit(pyramid.scripts.pserve.main())
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/scripts/pserve.py", line 316, in run
global_conf=vars)
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/scripts/pserve.py", line 340, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, **context.local_conf)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/util.py", line 58, in fix_call
reraise(*exc_info)
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/compat.py", line 23, in reraise
exec('raise t, e, tb', dict(t=t, e=e, tb=tb))
File "/users/is/pypi/egg_cache/p/PasteDeploy-1.5.2-py2.7.egg/paste/deploy/util.py", line 55, in fix_call
val = callable(*args, **kw)
File "/users/is/pypi/egg_cache/at/mytest-1.9.0-py2.7.egg//mytest/__init__.py", line 108, in main
File "/users/is/pypi/egg_cache/p/pyramid-1.5.1-py2.7.egg/pyramid/config/__init__.py", line 930, in scan
ignore=ignore)
File "/users/is/pypi/egg_cache/v/venusian-1.0a7-py2.7.egg/venusian/__init__.py", line 187, in scan
fn = loader.get_filename()
TypeError: zipimporter.get_filename() takes exactly 1 argument (0 given)
anyone could tell me how it comes?
Ok. I choose not to delete this question as I believe it might help other people who have the same problems.
Basically venusian does not support zipped egg. So when you produce your egg for pyramid, do not do it as zip egg.

Running Django Tests with a Precommit Hook

I would like to run all my django tests using mercurial's precommit hook. Whenever a test fails the commit will be aborted.
The goal is to block build-breaking commits as often as possible.
edit: Ended up using the external script route. Here is the reletant portion of my hgrc:
[hooks]
precommit = python ./pinax/projects/lgr/manage.py test lgr_photos --verbosity=0 --noinput
commit = hg push
Here is my progress on the hook function:
from os.path import join, dirname
import sys
from django.core.management import call_command
def hook(ui, repo, **kwargs):
project_path = join( dirname(repo.path), 'pinax', 'projects')
sys.path.insert(0, project_path)
from lgr.manage import *
output = call_command('test', verbosity=0, interactive=False)
#ui.warn(output)
What am I doing wrong here?
PS - It's giving a HUGE error traceback, which is included in it's entirety below
jim#ubuntu:~/workspace/lgr$ hg ci -m 'testing hooks'
No username found, using 'jim#ubuntu.ubuntu-domain' instead
error: precommit hook raised an exception: '_demandmod' object is not iterable
** unknown exception encountered, details follow
** report bug details to http://mercurial.selenic.com/bts/
** or mercurial#selenic.com
** Mercurial Distributed SCM (version 1.3.1)
** Extensions loaded:
Traceback (most recent call last):
File "/usr/bin/hg", line 27, in <module>
mercurial.dispatch.run()
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 16, in run
sys.exit(dispatch(sys.argv[1:]))
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 27, in dispatch
return _runcatch(u, args)
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 43, in _runcatch
return _dispatch(ui, args)
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 449, in _dispatch
return runcommand(lui, repo, cmd, fullargs, ui, options, d)
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 317, in runcommand
ret = _runcommand(ui, options, cmd, d)
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 501, in _runcommand
return checkargs()
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 454, in checkargs
return cmdfunc()
File "/usr/lib/pymodules/python2.6/mercurial/dispatch.py", line 448, in <lambda>
d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
File "/usr/lib/pymodules/python2.6/mercurial/util.py", line 402, in check
return func(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/mercurial/commands.py", line 667, in commit
node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
File "/usr/lib/pymodules/python2.6/mercurial/cmdutil.py", line 1213, in commit
return commitfunc(ui, repo, message, match(repo, pats, opts), opts)
File "/usr/lib/pymodules/python2.6/mercurial/commands.py", line 665, in commitfunc
editor=e, extra=extra)
File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 886, in commit
ret = self.commitctx(cctx, True)
File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 915, in commitctx
self.hook("precommit", throw=True, parent1=xp1, parent2=xp2)
File "/usr/lib/pymodules/python2.6/mercurial/localrepo.py", line 139, in hook
return hook.hook(self.ui, self, name, throw, **args)
File "/usr/lib/pymodules/python2.6/mercurial/hook.py", line 119, in hook
r = _pythonhook(ui, repo, name, hname, hookfn, args, throw) or r
File "/usr/lib/pymodules/python2.6/mercurial/hook.py", line 52, in _pythonhook
r = obj(ui=ui, repo=repo, hooktype=name, **args)
here is the important part:
File "/home/jim/run_lgr_tests.py", line 11, in hook
output = call_command('test', verbosity=0, interactive=False)
and the rest:
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 213, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 73, in activate
return real_activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 43, in delayed_loader
return g['real_%s' % caller](*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 205, in activate
_active[currentThread()] = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 180, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 84, in _demandimport
return _origimport(name, globals, locals, fromlist)
File "/home/jim/workspace/lgr/pinax/projects/lgr/apps/lgr_hacks.py", line 5, in <module>
User.email = models.EmailField(_('email address'), blank=True, max_length=200)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 62, in ugettext
return real_ugettext(message)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 286, in ugettext
return do_translate(message, 'ugettext')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 276, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 180, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 84, in _demandimport
return _origimport(name, globals, locals, fromlist)
File "/home/jim/workspace/lgr/pinax/apps/external_apps/djangodblog/__init__.py", line 1, in <module>
import djangodblog.admin
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 91, in _demandimport
return _origimport(name, globals, locals, fromlist)
File "/home/jim/workspace/lgr/pinax/apps/external_apps/djangodblog/admin.py", line 14, in <module>
admin.site.register(ErrorBatch, ErrorBatchAdmin)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py", line 90, in register
validate(admin_class, model)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/validation.py", line 22, in validate
models.get_apps()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 100, in get_apps
self._populate()
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 58, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/loading.py", line 74, in load_app
models = import_module('.models', app_name)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 84, in _demandimport
return _origimport(name, globals, locals, fromlist)
File "/home/jim/workspace/lgr/pinax/projects/lgr/apps/account/models.py", line 7, in <module>
from timezones.fields import TimeZoneField
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 103, in _demandimport
mod = _origimport(name, globals, locals)
File "/home/jim/workspace/lgr/pinax/apps/external_apps/timezones/fields.py", line 12, in <module>
default_tz = pytz.timezone(getattr(settings, "TIME_ZONE", "UTC"))
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 75, in __getattribute__
self._load()
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 47, in _load
mod = _origimport(head, globals, locals)
File "/home/jim/workspace/lgr/pinax/libs/external_libs/pytz-2008b/pytz/__init__.py", line 29, in <module>
from pkg_resources import resource_stream
File "/usr/lib/pymodules/python2.6/mercurial/demandimport.py", line 103, in _demandimport
mod = _origimport(name, globals, locals)
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2562, in <module>
working_set.require(__requires__)
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 626, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 505, in resolve
requirements = list(requirements)[::-1] # set up the stack
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2380, in parse_requirements
for line in lines:
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 1814, in yield_lines
for s in yield_lines(ss):
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 1813, in yield_lines
for ss in strs:
TypeError: '_demandmod' object is not iterable
It looks like Mercurial's way of importing modules is clashing with Django's somehow.
Before trying to dive in and sort that out, is there any reason to not just run the tests with the normal command?
[hooks]
precommit.runtests = python manage.py test

Categories