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

Fix missing filters for get settings validator #5480

Merged
merged 18 commits into from Sep 10, 2023

Conversation

wolflu05
Copy link
Contributor

This PR fixes the missing filters to get the settings validators for plugins to work again.

@netlify
Copy link

netlify bot commented Aug 25, 2023

Deploy Preview for inventree canceled.

Name Link
🔨 Latest commit b73de87
🔍 Latest deploy log https://app.netlify.com/sites/inventree/deploys/64fd97f157100c000829e5a8

@wolflu05 wolflu05 added bug Identifies a bug which needs to be addressed plugin Plugin ecosystem backport Apply this label to a PR to enable auto-backport action backport-to-0.12.x labels Aug 25, 2023
@wolflu05 wolflu05 added this to the 0.13.0 milestone Aug 25, 2023
@matmair
Copy link
Member

matmair commented Aug 27, 2023

@wolflu05 you might need to merge/wait for #5486 to fix the doc's errors

@SchrodingersGat
Copy link
Member

@wolflu05 please check out the CI errors

@wolflu05
Copy link
Contributor Author

wolflu05 commented Aug 28, 2023

Oh, I see, that is not the correct fix for my issue, will have to investigate why the clean function sometimes get the correct kwargs and sometimes not.

@wolflu05
Copy link
Contributor Author

wolflu05 commented Sep 2, 2023

I didn't manage to identify why I sometimes not get the kwargs but in the tests I get them. This is the easiest fix that works. Do you have a better idea of fixing the validators for plugins?

@SchrodingersGat
Copy link
Member

@wolflu05 happy with this fix, but given this might change some pretty low-level stuff, can you please provide some updated unit tests? In particular related to the edge cases you were seeing

@SchrodingersGat
Copy link
Member

@wolflu05 would you be able to throw in some extra unit tests here?

@wolflu05
Copy link
Contributor Author

wolflu05 commented Sep 9, 2023

@SchrodingersGat I now found the place where the clean function is called with additional kwargs which is against Django's implementation, so I removed the kwargs completely and replaced them with the self.get_filters_for_instance() function. I added two tests, one directly for the Settings and one more integrated into the plugin registry to make sure validators actually work with settings that have extra relations too. Now I only need to find out, why the test passes locally but not in CI.

@SchrodingersGat
Copy link
Member

These types of errors are always very frustrating to track down! Thanks for adding the tests

@wolflu05
Copy link
Contributor Author

wolflu05 commented Sep 10, 2023

@SchrodingersGat I found the culprit. I came across this after connecting via tmate and adding several prints to the code while running the tests over and over and see how far it runs. I then discovered that the validator doesn't run because it's not callable, but it is a static method which is strange. I then googled why static methods are sometimes not callable and found this. I then asked myself why it works on my machine and on ci not and then found out, I run python 3.10 in the devcontainer and ci is using 3.9. Python must have changed that behavior. I can validate that by running the provided snippet in the StackOverflow post. On my machine with 3.10 it returns True for both cases and on ci only for the direct check.

So TL;DR, make sure we don't use static methods for validators anywhere, as they are not marked as callable in some circumstances. The tests should pass now after moving the validator into the global scope as a normal function, so you can merge this finally.

@SchrodingersGat
Copy link
Member

@wolflu05 that's some fine detective work, well done!

@SchrodingersGat SchrodingersGat merged commit 9a6c2d2 into inventree:master Sep 10, 2023
21 checks passed
@github-actions
Copy link
Contributor

💔 All backports failed

Status Branch Result
0.12.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

backport --pr 5480

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

@wolflu05
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
0.12.x

Questions ?

Please refer to the Backport tool documentation

wolflu05 added a commit to wolflu05/InvenTree that referenced this pull request Sep 10, 2023
* Fix missing filters for get settings validator

* merge default model instance filters and kwargs

* Added tests for validators

* Give it a try without the kwargs passed to clean in save function

* Added string for identification for debug statement

* Added more debug comments

* Added more debug prints

* Fix test debug

* Modiefied workflow

* trigger ci

* Fix test and remove unused kwargs

* Added debug prints

* Only run one test in ci

* Added more debug code

* Remove all debug prints and reset workflow

* Reset overlooked file

(cherry picked from commit 9a6c2d2)

# Conflicts:
#	InvenTree/plugin/samples/integration/test_sample.py
SchrodingersGat pushed a commit that referenced this pull request Sep 11, 2023
* Fix missing filters for get settings validator (#5480)

* Fix missing filters for get settings validator

* merge default model instance filters and kwargs

* Added tests for validators

* Give it a try without the kwargs passed to clean in save function

* Added string for identification for debug statement

* Added more debug comments

* Added more debug prints

* Fix test debug

* Modiefied workflow

* trigger ci

* Fix test and remove unused kwargs

* Added debug prints

* Only run one test in ci

* Added more debug code

* Remove all debug prints and reset workflow

* Reset overlooked file

(cherry picked from commit 9a6c2d2)

# Conflicts:
#	InvenTree/plugin/samples/integration/test_sample.py

* Add missing import

* Added second missing import
@wolflu05 wolflu05 deleted the patch-1 branch February 15, 2024 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Apply this label to a PR to enable auto-backport action bug Identifies a bug which needs to be addressed plugin Plugin ecosystem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants