Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event/observers has severe bug #520

Closed
koenigseggposche opened this issue Nov 17, 2021 · 1 comment · Fixed by #526
Closed

event/observers has severe bug #520

koenigseggposche opened this issue Nov 17, 2021 · 1 comment · Fixed by #526
Labels
bug An existing feature is not working as intended

Comments

@koenigseggposche
Copy link

Describe the bug
all Class derived from Model are sharing the same observers !!!
causing event will fire multi times on all observers which listen to this event type

To Reproduce

from masoniteorm import Model

class A(Model):
    pass

class B(Model):
    pass

class AObserver:
    def booting(self, obj):
        print('Booting A %s' % obj)

class BObserver:
    def booting(self, obj):
        print('Booting B %s' % obj)

A.observe(AObserver())
B.observe(BObserver())

a = A()
# Booting A <__main__.A object at 0x000001AEBFC47220>
# Booting B <__main__.A object at 0x000001AEBFC47220>

print(id(A.__observers__) == id(B.__observers__))
# True

print(A.__observers__)
# [<__main__.AObserver object at 0x000001AEBFC65730>, <__main__.BObserver object at 0x000001AEBFC47910>]

Expected behavior
A() cause AObserver and BObserver both fired
and A.observers === B.observers is bugly TRUE

Desktop (please complete the following information):

  • OS: All platforms
  • Version: All

What database are you using?

  • Type: All
  • Version All
  • Masonite ORM latest(1.0)
@koenigseggposche koenigseggposche added the bug An existing feature is not working as intended label Nov 17, 2021
@Marlysson
Copy link
Contributor

@koenigseggposche Try define __observers__ = [] in your Model class level to solve this bug by right now while we solve without this changing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants