Open zvi-quantivly opened 10 months ago
I tried excluding self
inside DjangoDash.get_expanded_arguments()
(see here). Unfortunately, there was no difference.
@zvi-quantivly what is the driver behind wanting to embed the DjangoDash
instance inside a class? In particular, is there something specific that leads you to this code structure?
Yes. It's a little difficult to explain briefly, but I am working on a Django project that needs to be able to run user provided code as a “plugin”. Each plugin is written as a small Python package that depends on a common SDK and exposes a subclass of some base Plugin
class (from the SDK). These plugin subclasses are dynamically imported, initialized, and executed by the project. The initialization procedures populate specific plugin attributes with endpoints and authorization information that is required for its execution.
E.g., if we consider the example above, Base
provides something like self.run_query()
, which uses an attribute such as self.server_address
, which is populated by the Django project as part of the initialization of a plugin. The self.update_plot()
method needs to be able to use self.run_query()
to run. HTH.
It looks like the source of the problem is that setting method attributes on bound methods is disallowed [ref]. This happens in the custom callback()
decorator's func.expanded
assignment (here) whenever self.app.callback(...)(self.some_method)
is called (in which case, func
is a bound method). I still haven't found a solution for this. Now trying to think whether function objects (see second example here) might somehow work.
I have a requirement to create my Dash application within the context of a class. I tried following the example here to have something like:
However, this raises:
Since
self.app
is aDjangoDash
instance, so far, I haven't managed to figure out whyexpanded
isn't set. Any help resolving this would be greatly appreciated.EDIT: It seems it is caused by the inclusion of
self
(i.e., static methods are not effected).