Flask-AppBuilder AttributeError: 'tuple' object has no attribute 'columns' - python

I have a class "catalogue" in my database with multiple columns. Flask-AppBuilder however seems to miss them, as it throws AttributeError: 'tuple' object has no attribute 'columns'.
The table has 4 columns and it works fine if I specify them manually using the model but it fails with autoload using the flask_appbuilder Base object. Autoloading works for other tables. How can I get autoloading to work for this the catalogue table?
Schema
create table catalogue(
suffix VARCHAR(200) PRIMARY KEY,
label VARCHAR(200) NOT NULL,
CHECK (label <> ''),
type cataloguetype NOT NULL,
uri VARCHAR(229) GENERATED ALWAYS AS ('http://hitontology.eu/ontology/' || suffix) STORED
Code
from sqlalchemy import create_engine
from flask_appbuilder import Model, Base
engine = create_engine(config.SQLALCHEMY_DATABASE_URI)
class Catalogue(Base):
__table__= Table("catalogue", Base.metadata,autoload=True,autoload_with=engine)
Console Output
2020-08-28 12:34:08,809:INFO:flask_appbuilder.api:Registering route /api/v1/menu/ ['GET']
Traceback (most recent call last):
File "/home/konrad/projekte/hito/database-frontend/venv/bin/flask", line 8, in <module>
sys.exit(main())
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 967, in main
cli.main(args=sys.argv[1:], prog_name="python -m flask" if as_module else None)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 848, in run_command
app = DispatchingApp(info.load_app, use_eager_loading=eager_loading)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 305, in __init__
self._load_unlocked()
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 330, in _load_unlocked
self._app = rv = self.loader()
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 392, in load_app
app = locate_app(self, import_name, None, raise_if_not_found=False)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "/home/konrad/projekte/hito/database-frontend/app/__init__.py", line 32, in <module>
from . import views
File "/home/konrad/projekte/hito/database-frontend/app/views.py", line 6, in <module>
from .models import Softwareproduct, Catalogue, Classified#, interoperabilitystandard
File "/home/konrad/projekte/hito/database-frontend/app/models.py", line 59, in <module>
class Catalogue(Base):
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask_sqlalchemy/model.py", line 67, in __init__
super(NameMetaMixin, cls).__init__(name, bases, d)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/flask_sqlalchemy/model.py", line 121, in __init__
super(BindMetaMixin, cls).__init__(name, bases, d)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/api.py", line 76, in __init__
_as_declarative(cls, classname, cls.__dict__)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 131, in _as_declarative
_MapperConfig.setup_mapping(cls, classname, dict_)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 160, in setup_mapping
cfg_cls(cls_, classname, dict_)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 194, in __init__
self._early_mapping()
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 199, in _early_mapping
self.map()
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 695, in map
self.cls.__mapper__ = mp_ = mapper_cls(
File "<string>", line 2, in mapper
File "<string>", line 2, in __init__
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 139, in warned
return fn(*args, **kwargs)
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/orm/mapper.py", line 721, in __init__
self._configure_properties()
File "/home/konrad/projekte/hito/database-frontend/venv/lib/python3.8/site-packages/sqlalchemy/orm/mapper.py", line 1499, in _configure_properties
for column in self.persist_selectable.columns:
AttributeError: 'tuple' object has no attribute 'columns'

Related

No module named misc when implementing a simple pytest plugin?

I'm trying to implement the pytest plugin mentioned in https://github.com/pytest-dev/pytest/issues/2039, basically this plugin will print all tests that pytest finds:
## pytest_collector.py
import sys
import pytest
class DkPytestCollector(object):
def __init__(self):
self.collected = []
def pytest_collection_modifyitems(self, items):
for item in items:
self.collected.append(item.nodeid)
if __name__ == '__main__':
dkpytest_collector = DkPytestCollector()
directory = sys.argv[1]
pytest.main(['--collect-only', directory], plugins=[dkpytest_collector])
print('\n\nfound:')
for nodeid in dkpytest_collector.collected:
print(nodeid)
however, when I run it I get:
(dk) go|c:\srv\lib\dk> python ..\dkbuild\dkbuild\pytest_collector.py \srv\lib\dk
Traceback (most recent call last):
File "..\dkbuild\dkbuild\pytest_collector.py", line 20, in <module>
pytest.main(['--collect-only', directory], plugins=[dkpytest_collector])
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 50, in main
config = _prepareconfig(args, plugins)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 160, in _prepareconfig
pluginmanager=pluginmanager, args=args)
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 617, in __call__
return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 222, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 216, in <lambda>
firstresult=hook.spec_opts.get('firstresult'),
File "c:\srv\venv\dk\lib\site-packages\pluggy\callers.py", line 196, in _multicall
gen.send(outcome)
File "c:\srv\venv\dk\lib\site-packages\_pytest\helpconfig.py", line 68, in pytest_cmdline_parse
config = outcome.get_result()
File "c:\srv\venv\dk\lib\site-packages\pluggy\callers.py", line 77, in get_result
_reraise(*ex) # noqa
File "c:\srv\venv\dk\lib\site-packages\pluggy\callers.py", line 180, in _multicall
res = hook_impl.function(*args)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 943, in pytest_cmdline_parse
self.parse(args)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 1108, in parse
self._preparse(args, addopts=addopts)
File "c:\srv\venv\dk\lib\site-packages\_pytest\config.py", line 1071, in _preparse
self.pluginmanager.load_setuptools_entrypoints('pytest11')
File "c:\srv\venv\dk\lib\site-packages\pluggy\__init__.py", line 397, in load_setuptools_entrypoints
plugin = ep.load()
File "c:\srv\venv\dk\lib\site-packages\pkg_resources\__init__.py", line 2405, in load
return self.resolve()
File "c:\srv\venv\dk\lib\site-packages\pkg_resources\__init__.py", line 2411, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "c:\srv\venv\dk\lib\site-packages\_pytest\assertion\rewrite.py", line 212, in load_module
py.builtin.exec_(co, mod.__dict__)
File "c:\srv\venv\dk\lib\site-packages\py\_builtin.py", line 221, in exec_
exec2(obj, globals, locals)
File "<string>", line 7, in exec2
File "c:\srv\venv\dk\lib\site-packages\pytest_cov\plugin.py", line 6, in <module>
from coverage.misc import CoverageException
ImportError: No module named misc
if I pip uninstall pytest-cov everything works (well, except no coverage..)
How do I get this to work without uninstalling pytest-cov?

Running Pyramid app in Jython + pserve (waitress)

I installed Pyramid, SQLAlchemy and waitress running in virtualenv on Jython 2.7 (platform: Linux x64). Unfortunately pserve cannot start:
% pserve development.ini
Traceback (most recent call last):
File "/myapp/j1/ve/bin/pserve", line 11, in <module>
sys.exit(main())
File "/myapp/j1/ve/Lib/site-packages/pyramid/scripts/pserve.py", line 60, in main
return command.run()
File "/myapp/j1/ve/Lib/site-packages/pyramid/scripts/pserve.py", line 367, in run
server = self.loadserver(server_spec, name=server_name,
File "/myapp/j1/ve/Lib/site-packages/pyramid/scripts/pserve.py", line 409, in loadserver
return loadserver(
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 255, in loadserver
return loadobj(SERVER, uri, name=name, **kw)
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 269, in loadobj
context = loadcontext(
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 293, in loadcontext
return _loaders[scheme](
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 320, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 452, in get_context
context = self._context_from_use(
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 475, in _context_from_use
context = self.get_context(
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 404, in get_context
return loadcontext(object_type, name,
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 293, in loadcontext
return _loaders[scheme](
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 328, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 619, in get_context
entry_point, protocol, ep_name = self.find_egg_entry_point(
File "/myapp/j1/ve/Lib/site-packages/paste/deploy/loadwsgi.py", line 646, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/myapp/j1/ve/Lib/site-packages/pkg_resources/__init__.py", line 2229, in load
return self.resolve()
File "/myapp/j1/ve/Lib/site-packages/pkg_resources/__init__.py", line 2235, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/myapp/j1/ve/Lib/site-packages/waitress/__init__.py", line 1, in <module>
from waitress.server import create_server
File "/myapp/j1/ve/Lib/site-packages/waitress/server.py", line 22, in <module>
from waitress.adjustments import Adjustments
File "/myapp/j1/ve/Lib/site-packages/waitress/adjustments.py", line 47, in <module>
class Adjustments(object):
File "/myapp/j1/ve/Lib/site-packages/waitress/adjustments.py", line 167, in Adjustments
socket_options = [
AttributeError: 'module' object has no attribute 'SOL_TCP'
Is there some workaround for this?

Django multisite: ValueError: SITE_ID has not been set

I recently got a new computer and have been trying to set my development environment back up, which right now I need to develop a Django project. However, I keep running into this following error whenever I try to do python manage.py runserver, makemigrations, migrate, etc and I don't understand why.
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/usr/local/lib/python2.7/site-packages/debug_toolbar/apps.py", line 15, in ready
dt_settings.patch_all()
File "/usr/local/lib/python2.7/site-packages/debug_toolbar/settings.py", line 232, in patch_all
patch_root_urlconf()
File "/usr/local/lib/python2.7/site-packages/debug_toolbar/settings.py", line 220, in patch_root_urlconf
reverse('djdt:render_panel')
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 550, in reverse
app_list = resolver.app_dict[ns]
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 352, in app_dict
self._populate()
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 285, in _populate
for pattern in reversed(self.url_patterns):
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 402, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 396, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/Lily/Sites/StartupTree/StartupTree/urls.py", line 48, in <module>
+ static(settings.STATIC_URL, document_root=settings.STATICFILES_DIRS[0])
File "/usr/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 33, in include
urlconf_module = import_module(urlconf_module)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/Lily/Sites/StartupTree/branch/urls.py", line 2, in <module>
from branch.views import (
File "/Users/Lily/Sites/StartupTree/branch/views/__init__.py", line 15, in <module>
from app.views import home as home_redirect
File "/Users/Lily/Sites/StartupTree/app/views.py", line 5, in <module>
from emailuser.views import user_login as login_redirect
File "/Users/Lily/Sites/StartupTree/emailuser/views/__init__.py", line 32, in <module>
from branch.modelforms import (
File "/Users/Lily/Sites/StartupTree/branch/modelforms.py", line 139, in <module>
class ExperienceForm(forms.ModelForm):
File "/usr/local/lib/python2.7/site-packages/django/forms/models.py", line 285, in __new__
opts.help_texts, opts.error_messages)
File "/usr/local/lib/python2.7/site-packages/django/forms/models.py", line 212, in fields_for_model
formfield = f.formfield(**kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1981, in formfield
'queryset': self.rel.to._default_manager.using(db),
File "/usr/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/contrib/sites/managers.py", line 66, in get_queryset
**{self._get_field_name() + '__id': settings.SITE_ID})
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 679, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/query.py", line 697, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1309, in add_q
clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1337, in _add_q
allow_joins=allow_joins, split_subq=split_subq,
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1208, in build_filter
condition = self.build_lookup(lookups, col, value)
File "/usr/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1101, in build_lookup
return final_lookup(lhs, rhs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 101, in __init__
self.rhs = self.get_prep_lookup()
File "/usr/local/lib/python2.7/site-packages/django/db/models/lookups.py", line 139, in get_prep_lookup
return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 727, in get_prep_lookup
return self.get_prep_value(value)
File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 985, in get_prep_value
return int(value)
File "/usr/local/lib/python2.7/site-packages/multisite/threadlocals.py", line 57, in __int__
return self.get_default()
File "/usr/local/lib/python2.7/site-packages/multisite/threadlocals.py", line 119, in get_default
raise ValueError('SITE_ID has not been set.')
ValueError: SITE_ID has not been set.
I've checked my settings.py and found SITE_ID = 1 so I'm assuming that's what it wants? (I'm also very new to Django, sorry!)
Thanks so much in advance for your help!
When using django-multisite you need to set up the SITE_ID as follows
from multisite import SiteID
SITE_ID = SiteID()
From command line intro your enviroment:
$ export SITE_ID = 1

Mysterious "'module' object has no attribute" error

Every time I try to serve my project I get this error:
Traceback (most recent call last):
File "/usr/bin/pserve", line 9, in <module>
load_entry_point('pyramid==1.5.2', 'console_scripts', 'pserve')()
File "/usr/lib/python3.4/site-packages/pyramid-1.5.2-py3.4.egg/pyramid/scripts/pserve.py", line 51, in main
return command.run()
File "/usr/lib/python3.4/site-packages/pyramid-1.5.2-py3.4.egg/pyramid/scripts/pserve.py", line 313, in run
relative_to=base, global_conf=vars)
File "/usr/lib/python3.4/site-packages/pyramid-1.5.2-py3.4.egg/pyramid/scripts/pserve.py", line 344, in loadserver
server_spec, name=name, relative_to=relative_to, **kw)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 255, in loadserver
return loadobj(SERVER, uri, name=name, **kw)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 271, in loadobj
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 320, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 454, in get_context
section)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 476, in _context_from_use
object_type, name=use, global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 406, in get_context
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 328, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 620, in get_context
object_type, name=name)
File "/usr/lib/python3.4/site-packages/PasteDeploy-1.5.2-py3.4.egg/paste/deploy/loadwsgi.py", line 646, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2320, in load
return self.resolve()
File "/usr/lib/python3.4/site-packages/pkg_resources/__init__.py", line 2326, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/__init__.py", line 1, in <module>
from waitress.server import create_server
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/server.py", line 23, in <module>
from waitress.channel import HTTPChannel
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/channel.py", line 28, in <module>
from waitress.task import (
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/task.py", line 53, in <module>
class ThreadedTaskDispatcher(object):
File "/usr/lib/python3.4/site-packages/waitress-0.8.9-py3.4.egg/waitress/task.py", line 57, in ThreadedTaskDispatcher
start_new_thread = thread.start_new_thread
AttributeError: 'module' object has no attribute 'start_new_thread'
The weird thing is, the thread module has the attribute start_new_thread
>>> from waitress.compat import (thread, Empty)
>>> thread.start_new_thread
<built-in function start_new_thread>
I started this pyramid project using python 2.7, and I am trying to switch it over to python 3.4.
Things I've tried:
updating the waitress module, it's already up to date
scratching my head

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