-
Notifications
You must be signed in to change notification settings - Fork 92
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
has_changed incompatible with model with vector_fields #132
Comments
Hi, can you give an example of how you're using the hook? i.e.: @hook(AFTER_SAVE, has_changed=True)
This is the expected behaviour |
I can see that could make sense, but it's ambiguous when using Perhaps it would be better if |
I'm sorry but I'm not sure if I understand what you want to achieve. Could you write in words when you expect your hooks to be fired so I can help you better? |
I have firstname, last name username fields on the Player model (a User subclass). I use these to create a text embedding of a combined string f"{firstname} {last_name} {username}. I have a function that calls the OpenAI API to generate the embedding. I want this to be called:
I don't want it to be called if other fields on the Player model change, so would like the has_changed flag to apply only to the fields mentioned in the AFTER_SAVE decorator. |
That's how it works. This should do the trick, it will fire the hook when any of these changes. class Player(LifecycleModelMixin, AbstractUser):
name_embedding = VectorField(dimensions=1536, blank=True, null=True)
@hook(AFTER_CREATE)
@hook(AFTER_SAVE, when_any=["username", "first_name", "last_name"], has_changed=True)
def update_name_embedding(self):
... |
Any update on this? I am also facing this issue and adding the What does seem to resolve this is overriding the
But this seems pretty hacky. |
I just added a django-pgvector VectorField to my model and am now having an issue with using
has_changed
.The error is
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
.The source of the error is /mixins.py", line 91, in _diff_with_initial
This doesn't happen if is_changed=False but if True then every field in the model is checked for changes.
I think there are two issues here:
Cheers!
The text was updated successfully, but these errors were encountered: