fdegrave / djangodoo

Django app to ease the interactions between Django and Odoo
Other
53 stars 20 forks source link

Avoid the introduction of a single-point failure #3

Open tvanesse opened 8 years ago

tvanesse commented 8 years ago

Following my last comment in PR #2 , I'd like to make sure djangodoo does not introduce any unneeded dependency between a Django project using djangodoo and the availability of an Odoo instance.

I imagine the raise statement at line 93 in init.py could be handled with some logic that would mark OdooModel as "currently unavailable" so that any reference to an OdooModel object defined in the user's application will chain a RuntimeException that can be handled in any desired way by the developer.

I'm thinking of adding some lines at the end of __init__.py like

def mark_odoo_unavailable():
    # do something
    pass

try:
    set_auth_cache()
    set_odoo_client()
except:
    # The Odoo instance is currently unavailable
    class_prepared.connect(mark_odoo_unavailable)
# Everything worked as expected
class_prepared.connect(add_extra_model_fields, dispatch_uid="FQFEQ#rfq3r")

and then in the user application

try:
    from djangodoo.models import OdooModel    # this should possibly raise an exception

    class Partner(OdooModel):
        _odoo_model = "res.partner"
        _odoo_fields = [
            'name',
            'customer',
            ...
            'user_id'
        ]
except:
    # Do whatever you want to handle the fact that Odoo is not available.
    # That includes simply ignoring the error.

@fdegrave this is just a very basic idea and I'd like to hear your take on that. I am not convinced this is the best solution and I'm not familiar with the underlying mechanisms of Django that could potentially simplify the implementation of this feature. How would you implement it?

tvanesse commented 8 years ago

Up @fdegrave

fdegrave commented 8 years ago

Hi Thomas!

Thank you for the suggestion, and sorry for the late answer (I'm just back from holidays). I think your proposal is a good -- and quick to implement -- starting point to improve the robustness of the system.

I was also thinking of saving the Odoo model description locally and use it if the Odoo server is unreachable -- and just log a warning in that case. I'll do that as soon as I have some free time.

Cheers,

F.