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

__qualname__ #3

Closed
jellevandehaterd opened this issue Dec 17, 2015 · 4 comments
Closed

__qualname__ #3

jellevandehaterd opened this issue Dec 17, 2015 · 4 comments

Comments

@jellevandehaterd
Copy link

I am currently experimenting with eventsourcing and django and I am getting the following error;
AttributeError: type object has no attribute __qualname__
from the ObjectJSONEncoder, it expects obj.__class__.__qualname__ to exist

It would be nice to be able to inject my own ObjectJSONEncoder/Decoder

@johnbywater
Copy link
Collaborator

Hey I'm really sorry for the delay, I only saw this issue was open yesterday.

I just pushed 7f9dd66; some changes (to the develop branch) that allow custom JSON encoder/decoder to be passed as application constructor parameters. Does that help?

I'm really interested to hear about how you are using it with Django. Do you think it would make sense to make something that works like a normal Django model? I'm just about to start a Django project to make a user interface for an event sourcing application, and would be really interested to hear your thoughts.

@johnbywater
Copy link
Collaborator

Also FYI to get a __qualname__ attribute on a class you can use QualnameABCMeta as the meta class. For example, see the DomainEvent class. Both are in model/events.py.

The __qualname__ is needed primarily because the domain event classes are nested in the domain entity classes, and the event topic needs to have both so that the domain event topic can be resolved to a domain event class when a domain event is reconstituted from a stored event. If other object instances are set on the domain event, they are also expected by the default JSON encoder/decoder to have a __qualname__ attribute in case they happen to be nested. In Python 2, there is no way to tell when (where) a class is nested, unless you fix up something like QualnameABCMeta. As I'm sure you know, object classes in Python 3 already have a __qualname__ attribute.

@jellevandehaterd
Copy link
Author

Hey Now the delay is on my side ;-) Just got back from my holiday.
Thnx for the update!. Updating to the development branch now.

I’m currently developing an app with Django (v1.8.x) and Django-oscar and it would be very useful to use event sourcing for some parts op the app. Currently I am focussing on subscriptions.
For the database I’m using Postgres v9.4 (Because of the JSONB field ;-) The 'DjangoStoredEvent’ model uses the JsonBfield http://djangonauts.github.io/django-pgjson/ (or the native JSONfield https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#jsonfield for Django v1.9+ ) for ‘event_attrs’ so its effectively an documentstore with indexing capabilities and loads of other nice features. The django models stored in Json break the ObjectJsonEnecoder because of the missing qualname (Using python 2.7.x) so with this update I hopefully can try fix this. I tried adding the QualnameABCMeta as metaclass which resulted in al kinds of multimetaclass hell ;-)

Keep up the good work!

Op 27 dec. 2015, om 23:57 heeft John Bywater notifications@github.com het volgende geschreven:

Hey I'm really sorry for the delay, I only saw this issue was open yesterday.

I just pushed 7f9dd66 7f9dd66;
some changes (to the develop branch) that allow custom JSON encoder/decoder to be passed as application constructor parameters. Does that help?

I'm really interested to hear about how you are using it with Django. Do you think it would make sense to make something that works like a normal Django model? I'm just about to start a Django project to make a user interface for an event sourcing application, and would be really interested to hear your thoughts.


Reply to this email directly or view it on GitHub #3 (comment).

@johnbywater
Copy link
Collaborator

Thanks! I got distracted. I'd love to chat with you about making a django-eventsourcing package. I just setup a mailing list for this project, it would be great if you were to join ;-). Hoping to discuss these things further with you soon...
https://groups.google.com/forum/#!forum/eventsourcing-users

johnbywater pushed a commit that referenced this issue Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants