-
Notifications
You must be signed in to change notification settings - Fork 132
Hooks do not fire reliably with "+" option #21
Comments
@briankung If you find the time to make a pull request I can happily take a look and merge it in. |
Hey, sorry, I couldn't devote enough time to figure out how to write a simple test for it. The function is difficult to test. I could submit a PR without a test, but that makes me uncomfortable. |
Would it be correct to set user_override to False |
@briankung I believe you assessment is correct. If we changed I merged this enhancement in via a pull-request from another developer. In an effort to be thorough I am CC'ing @GVRV to make sure such a change wouldn't create unintended consequences. I doubtful that this is a consequence of using different Django versions. I will still be looking into a way to confirm expected behavior via a unit test. |
I can confirm this is a bug having spent two hours trying to confirm the same thing (without looking at the open issues! Idiot!). #21 (comment) is the correct fix. The unit tests on this don't provide enough existing coverage to making adding a test just for this a short task! Are you still set on not patching without one? |
Addresses #21 Currently, when the "+" option is set for a hook event. Only hooks were the user id is 1 will actually fire. This is because True translates to 1 when the ORM converts the query to SQL. This change should now have the correct user_override value set when find_and_fire_hook is called. In an effort to move this issue forward I am pushing the change proposed in #21 without a unit test.
@imsickofmaps I have pushed the change in b3387f6 Pull from master and let me know if that addresses this issue. I can then move to make a release. |
👍 works for me... thanks! |
@avelis can we have a release now? |
Agreed - the changes work. |
I confirm the change fixes the problem. |
Fixed and released in v1.2.2. Release has also been pushed to PyPi. Links: |
@avelis --> |
I noticed that hooks with the "+" option were not being triggered for all users as I'd expected from the documentation - at least, not reliably.
From the documentation:
However, in
utils.py
,user_override
looks like it is set toTrue
if there is a plus sign: https://github.com/zapier/django-rest-hooks/blob/master/rest_hooks/utils.py#L82In
find_and_fire_hook
, meanwhile,user_override=True
is not accounted for:Setting
filters['user'] = user_override
results infilters['user'] = True
. This means thatHook.objects.filter(**filters)
will filter foruser=True
. I was very confused what that meant - I thought it reasonable to assume that it would might be equivalent touser__isnull=False
, but the actual result is stranger. I tested it with a few of our own models.It turns out that if you ask for
SoAndSoModel.objects.filter(related_object=True)
, Django castsrelated_object=True
torelated_object_id=1
andrelated_object=False
torelated_object_id=0
in the query.Which means that
rest_hooks
is only returning hooks whereuser_id=1
.That's my theory, anyway. If I have a moment later, I'll write a test to confirm.
The text was updated successfully, but these errors were encountered: