get bs_module from sys.modules, not directly from `__import__`() #4

Merged
merged 1 commit into from Nov 4, 2011

Projects

None yet

2 participants

@bmathieu33
Contributor

__import__() returns the top-level module of a package, not the module itself. __import__() + sys.modules is the way recommanded by the python documentation:

http://docs.python.org/library/functions.html#__import__ (see last example)

My django packages are in a nested namespace (2 levels): top.package1, top.package2,...

Without this patch, the job list is located in "top" module, and the jobs are listed twice (or more if you have more packages in "top.*" and beanstalk jobs. This can be confusing for the user, although jobs are properly registered.

With my patch, the job list is properly locate in top.package.1.beanstalk_jobs, top.package2.beanstalk_jobs, and so on.

I have also set __module__ attribute of the decorator to reflect __module__ attribute of the decorated function (not exactly a clean functools.wraps, but it can help debugging)

@bmathieu33 bmathieu33 get bs_module from sys.modules, not directly from __import__()
__import__ returns the top-level module of a package, not the module itself.
a89419f
@jonasvp jonasvp merged commit 6173a4c into jonasvp:master Nov 4, 2011
@jonasvp
Owner
jonasvp commented Nov 4, 2011

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment