Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Solution-resistant AttributeError: 'modle' object has no attribute...

148 views
Skip to first unread message

Dan Stromberg

unread,
Jul 10, 2014, 12:41:22 PM7/10/14
to Python List, isaac...@soterawireless.com
Hi folks.

I'm having trouble with a strange AttributeError. I'm using RQ (Redis
Queue) and Django, both of which are new to me, so perhaps they are
somehow relevant.

Anyway, the traceback looks like:
Traceback (most recent call last):
File "/home/ec2-user/miniconda/envs/sciencedb/lib/python2.7/site-packages/rq/worker.py",
line 479, in perform_job
rv = job.perform()
File "/home/ec2-user/miniconda/envs/sciencedb/lib/python2.7/site-packages/rq/job.py",
line 466, in perform
self._result = self.func(*self.args, **self.kwargs)
File "/home/ec2-user/science_server/higgins/tasks.py", line 276, in
session_retrieval_manager
dummy = higgins.models.extract_guid_from_visi_filename
AttributeError: 'module' object has no attribute
'extract_guid_from_visi_filename'

But looking in higgins/models.py, I see a def for
extract_guid_from_visi_filename.

Here's a list of things I've checked/tried, compiled from the first
two pages of google hits on the error, and a couple of my own guesses:
# circular dependency in imports? No.
# module of same name? No, because __file__ looks correct
# Not in Django's settings.py's INSTALLED_APPS? No, higgins is
present in INSTALLED_APPS
# No __init__.py? There is an __init__.py in the higgins directory
# Old .pyc? No, I've removed it and same result
# __all__ present? No
# Need to from module import function? No, does not help.

BTW, pylint doesn't flag an error.

BTW, I can import and retrieve the function fine in django's "python
manage.py shell".

If I sys.stderr.write the module's __file__, it gives a full path that
looks as expected.

If I sys.stderr.write(dir(higgins.models)), it has some of the symbols
from higgins.models, but some of them are missing, including the
function I want. It's as though an old version of the module is being
seen, rather than the current version.

Anyone have any (further) suggestions for me?

Thanks!

Chris Angelico

unread,
Jul 10, 2014, 12:58:04 PM7/10/14
to Python List
On Fri, Jul 11, 2014 at 2:41 AM, Dan Stromberg <drsa...@gmail.com> wrote:
> It's as though an old version of the module is being
> seen, rather than the current version.
>
> Anyone have any (further) suggestions for me?
>

Wipe out *.pyc and try again? Restart any processes that are running
Django, in case they have it cached in memory?

This is something Python isn't really designed for (coping with
multiple versions of a module simultaneously). The Python import
machinery seems to assume that, across one process's lifetime, all .py
and .pyc (etc) files ever used will remain pristine, and can safely be
cached etc. There's no good mechanism for saying "Hey, Python, I just
updated this file, can you load the new version please?" - every
method I've seen for doing so seems to require fiddling around with
internals, and/or extreme risk of getting the wrong version.

ChrisA

Dan Stromberg

unread,
Jul 10, 2014, 1:23:37 PM7/10/14
to Python List
On Thu, Jul 10, 2014 at 9:41 AM, Dan Stromberg <drsa...@gmail.com> wrote:
> Hi folks.
>
> I'm having trouble with a strange AttributeError. I'm using RQ (Redis
> Queue) and Django, both of which are new to me, so perhaps they are
> somehow relevant.
>
> Anyway, the traceback looks like:
> Traceback (most recent call last):
> File "/home/ec2-user/miniconda/envs/sciencedb/lib/python2.7/site-packages/rq/worker.py",
> line 479, in perform_job
> rv = job.perform()
> File "/home/ec2-user/miniconda/envs/sciencedb/lib/python2.7/site-packages/rq/job.py",
> line 466, in perform
> self._result = self.func(*self.args, **self.kwargs)
> File "/home/ec2-user/science_server/higgins/tasks.py", line 276, in
> session_retrieval_manager
> dummy = higgins.models.extract_guid_from_visi_filename
> AttributeError: 'module' object has no attribute
> 'extract_guid_from_visi_filename'

It turned out I needed to restart my RQ (Redis Queue) processes.

Joel Goldstick

unread,
Jul 10, 2014, 1:31:56 PM7/10/14
to Dan Stromberg, isaac...@soterawireless.com, Python List
Do you need to add parens? is this a method, not at attribute?
dummy = higgins.models.extract_guid_from_visi_filename()

>
> But looking in higgins/models.py, I see a def for
> extract_guid_from_visi_filename.
>
> Here's a list of things I've checked/tried, compiled from the first
> two pages of google hits on the error, and a couple of my own guesses:
> # circular dependency in imports? No.
> # module of same name? No, because __file__ looks correct
> # Not in Django's settings.py's INSTALLED_APPS? No, higgins is
> present in INSTALLED_APPS
> # No __init__.py? There is an __init__.py in the higgins directory
> # Old .pyc? No, I've removed it and same result
> # __all__ present? No
> # Need to from module import function? No, does not help.
>
> BTW, pylint doesn't flag an error.
>
> BTW, I can import and retrieve the function fine in django's "python
> manage.py shell".
>
> If I sys.stderr.write the module's __file__, it gives a full path that
> looks as expected.
>
> If I sys.stderr.write(dir(higgins.models)), it has some of the symbols
> from higgins.models, but some of them are missing, including the
> function I want. It's as though an old version of the module is being
> seen, rather than the current version.
>
> Anyone have any (further) suggestions for me?
>
> Thanks!
> --
> https://mail.python.org/mailman/listinfo/python-list



--
Joel Goldstick
http://joelgoldstick.com

Steven D'Aprano

unread,
Jul 10, 2014, 6:50:52 PM7/10/14
to
On Thu, 10 Jul 2014 13:31:56 -0400, Joel Goldstick wrote:

>> dummy = higgins.models.extract_guid_from_visi_filename
>> AttributeError: 'module' object has no attribute
>> 'extract_guid_from_visi_filename'
>
> Do you need to add parens? is this a method, not at attribute?
> dummy = higgins.models.extract_guid_from_visi_filename()


That cannot be the solution. Before extract_guid_from_visi_filename can
be called, it first has to be looked up, and that fails with

AttributeError: 'module' object has no attribute
'extract_guid_from_visi_filename'


Whenever I get a mysterious "module has no such attribute" error, I
immediately check two things:

- check for typos: have I misspelled the function I want?

- check for shadowing: am I looking in the module I think I'm
looking? have I accidentally added a module with the same name?



--
Steven
0 new messages