Problems with creating new ModelConditionSet for Gargoyle

61 views
Skip to first unread message

Lyubomir Petrov

unread,
Jan 16, 2011, 11:34:36 PM1/16/11
to disqus-o...@googlegroups.com
Hi all,
First of all - thanks for the wonderful code released recently from the Disqus team, good work boys! :)

Now, about the problem - tried this example from the documentation of Gargoyle:
class SiteConditionSet(conditions.ModelConditionSet):
    percent = conditions.Percent()
    domain = conditions.String()

gargoyle.register(SiteConditionSet(Site))

And seems that its registered just fine..but when the get_all_conditions method of the manager is called - it returns only those that are defined in builtins.py.

Its weird, still debugging the problem, but if someone have a solution - please help :)


David Cramer

unread,
Jan 16, 2011, 11:45:08 PM1/16/11
to disqus-o...@googlegroups.com
Sounds like it may not be registering correctly in that situation. Will try to get a fix in for this tomorrow.

Thanks for the report :)

-- 
David Cramer

Liubomir Petrov

unread,
Jan 17, 2011, 12:37:41 AM1/17/11
to disqus-o...@googlegroups.com
Hi again,
10x a lot, for the quick answer :)

Forgot to mention, that I'm using gargoyle and nexus into a sub folder:

INSTALLED_APPS = (
   ...
   'libs.nexus',
   'libs.gargoyle',
)
 
Best regards,
Lyubomir Petrov

Liubomir Petrov

unread,
Jan 17, 2011, 2:06:06 AM1/17/11
to disqus-o...@googlegroups.com
Hi again,
I think that I've found the problem - since G
argoyle is trying to autodiscover files with name "gargoyle.py" into app's folder and those files requires an "from gargoyle import gargoyle" it somehow makes 2 different includes (and thats why) - 2 different global objects of type SwitchManager (the first with only 1 item into _registry - my custom condition set and in the second - 2 items - the builtin condition sets).

If I'm right, the simplest solution will be to use different file name - my patch attached, but not heavily tested - so I'll be waiting for confirmation if everything is ok :)

Best regards,
Lyubomir Petrov
__init__.patch

David Cramer

unread,
Jan 17, 2011, 3:19:24 PM1/17/11
to disqus-o...@googlegroups.com
Ah that is indeed the problem. I'm really not sure the best way to handle this. I guess we should change everything to import gargoyle from the __init__ file (and maybe instantiate it there).

Going to work up a changeset now. Thanks again!

-- 
David Cramer
Attachments:
- __init__.patch

Liubomir Petrov

unread,
Jan 17, 2011, 3:34:26 PM1/17/11
to disqus-o...@googlegroups.com
Ok, I will pause and wait for the upcoming changes this night :)
Btw, the patch does fixes some issues, but still there is something weird going on when I press "add" to my new custom condition I got some KeyErrors and similar.
If you want I cant take a deeper look into the code now and supply a patch?

Best regards,
Lyubomir Petrov

David Cramer

unread,
Jan 17, 2011, 3:45:11 PM1/17/11
to disqus-o...@googlegroups.com
This should solve the problem. I removed all references of gargoyle.models.gargoyle and its now only available at gargoyle.gargoyle. 


-- 
David Cramer

Liubomir Petrov

unread,
Jan 17, 2011, 8:18:56 PM1/17/11
to disqus-o...@googlegroups.com
Tested the changeset and it works perfect, except...
When I call in my app: app/gargoyle.py
from gargoyle import gargoyle
from gargoyle import conditions

It says that conditions and gargoyle are not found in module gargoyle. After some debug I found that it tries to import my app.gargoyle, not the libs.gargoyle.gargoyle module.
Again if I change the import to use libs.gargoyle there are 2 different SwitchManager's initialized. I'm not sure if this is a normal behavior of python, but since I have added . and ./libs/ to my import path I can import 2 times the same module as different instance. (Note: Python2.7/Windows/Devserver_plus + Werkzeug).

So I'd applied again my solution:
 - imp.find_module('gargoyles', app_path)
Is there a better way of fixing this?
I've been using this folder structure/import path for the last few months for several projects and I'd never found any problems on any 3rd party Django app, but still - if you think that the problems are from my way of loading external apps, I'll be happy to thing some way of fixing it :)

And again - 10x for the good support. I will do some testing now and if it fits my needs, I'll definitely try to contribute some DTL templatetags or whatever I found usable while implementing it into my project :)

Best regards,
Lyubomir Petrov

Wes Winham

unread,
Jan 24, 2011, 4:21:47 PM1/24/11
to disqus-opensource
My solution to this issue was to rename the expected myapp/gargoyle.py
to myapp/gargolye_conditions.py : https://github.com/winhamwr/gargoyle/tree/condition_rename

Looking for "gargoyle" it seems like you're going to shadow one or the
other depending on your python path setup.

-Wes

On Jan 17, 8:18 pm, Liubomir Petrov <liubomir.pet...@gmail.com> wrote:
> Tested the changeset and it works perfect, except...
> When I call in my app: app/gargoyle.py
> from gargoyle import gargoyle
> from gargoyle import conditions
>
> It says that conditions and gargoyle are not found in module gargoyle. After
> some debug I found that it tries to import my app.gargoyle, not the
> libs.gargoyle.gargoyle module.
> Again if I change the import to use libs.gargoyle there are 2 different
> SwitchManager's initialized. I'm not sure if this is a normal behavior of
> python, but since I have added . and ./libs/ to my import path I can import
> 2 times the same module as different instance. (Note:
> Python2.7/Windows/Devserver_plus + Werkzeug).
>
> So I'd applied again my solution:
>  - imp.find_module('gargoyle*s*', app_path)
> Is there a better way of fixing this?
> I've been using this folder structure/import path for the last few months
> for several projects and I'd never found any problems on any 3rd party
> Django app, but still - if you think that the problems are from my way of
> loading external apps, I'll be happy to thing some way of fixing it :)
>
> And again - 10x for the good support. I will do some testing now and if it
> fits my needs, I'll definitely try to contribute some DTL templatetags or
> whatever I found usable while implementing it into my project :)
>
> Best regards,
> Lyubomir Petrov
>
>
>
>
>
>
>
> On Mon, Jan 17, 2011 at 10:45 PM, David Cramer <dcra...@gmail.com> wrote:
> >  This should solve the problem. I removed all references of
> > gargoyle.models.gargoyle and its now only available at gargoyle.gargoyle.
>
> >https://github.com/disqus/gargoyle/commit/da27005bf5d16b3b5a23f11823e...
>
> > --
> > David Cramer
>
> > On Monday, January 17, 2011 at 12:34 PM, Liubomir Petrov wrote:
>
> > Ok, I will pause and wait for the upcoming changes this night :)
> > Btw, the patch does fixes some issues, but still there is something weird
> > going on when I press "add" to my new custom condition I got some KeyErrors
> > and similar.
> > If you want I cant take a deeper look into the code now and supply a patch?
>
> > Best regards,
> > Lyubomir Petrov
>

Craig

unread,
Jun 29, 2011, 6:41:08 AM6/29/11
to disqus-o...@googlegroups.com
Em segunda-feira, 24 de janeiro de 2011 21h21min47s UTC, Wes Winham escreveu:
My solution to this issue was to rename the expected myapp/gargoyle.py
to myapp/gargolye_conditions.py : https://github.com/winhamwr/gargoyle/tree/condition_rename

Looking for "gargoyle" it seems like you're going to shadow one or the
other depending on your python path setup.

-Wes

I had this problem, which was solved by using your fork. 
Reply all
Reply to author
Forward
0 new messages