Repository: django-json-api/django-rest-framework-json-api

Issue:
Validation of included_resources fails when nested
## Description of the Bug Report

#900 introduced validation of `included_resources` but causes a regression that when one of `included_serializers` of the current serializer of called view uses `included_resources` it will fail.

I assume validation of `included_resources` should actually be done in the serializer meta class and only query parameters validated in `IncludedResourcesValidationMixin`. 

See discussion #318 where there is also some code to reproduce it.

## Checklist

- [x] Certain that this is a bug (if unsure or you have a question use [discussions](https://github.com/django-json-api/django-rest-framework-json-api/discussions) instead)
- [x] Code snippet or unit test added to reproduce bug



Discussion:
As a follow up I question whether it is a good idea to validate include query parameters in init of a serializer as init can be called anytime. Better to be moved to `QueryParameterValidationFilter`.
@sliverc  Is this at all related to this problem I am facing.  I just upgraded a django 1.11 app up to latest and upgrded all django related dependencies to latest at the same time.

I am hitting an endpoint that maps to the AccountLicenseViewSet (I included the classes below).  It gets and serializes the initial queryset fine.  However, when it gets into the restframeworkjsonapi renderer.  While initializing the related serializer, `field = serializer_class(relation_instance, many=many, context=context)`, it calls `this_serializer_class = view.get_serializer_class()` to, but this returns the `AccountLicenseSerializer` rather than the `AccountSerializer`.  So when gets into the `validate_path` method, it fails and throws an error because it is trying to look up the related serializer on the `AccountLicenseSerializer` instead of the `AccountSerializer`.

This is all working on perfectly on the 1.11 django project that is still running on another computer I have.  But it is now failing here.  Is this possibly related to the issue you mentioned?

![image](https://user-images.githubusercontent.com/4825257/122483553-dc241000-cfa0-11eb-8392-95358823f609.png)


AccountLicenseViewSet
```
class AccountLicenseViewSet(BaseViewSet):
    serializer_class = AccountLicenseSerializer
    model = AccountLicense
    filter_fields = ['account__id']
    permission_classes = [IsAuthenticated, Or(IsReadOnlyRequest, IsAdmin, IsSameUser)]
```

AccountLicenseSerializer
```
class AccountLicenseSerializer(serializers.ModelSerializer):
    included_serializers = {
        'account': 'core.serializers.AccountSerializer',
        'app': 'core.serializers.AppSerializer'
    }

    app_id = serializers.SerializerMethodField()

    class Meta:
        model = AccountLicense
        fields = '__all__'

    class JSONAPIMeta:
        included_resources = ['account', 'app']

    def get_app_id(self, obj):
        return obj.app.id
```

```
class AccountSerializer(serializers.ModelSerializer):
    included_serializers = {
        'account_account_users': AccountUserSerializer,
        'account_license': AccountLicenseSerializer
    }

    account_account_users = ResourceRelatedField(
        queryset=AccountUser.objects.filter(role="owner"),
        # read_only=True,
        many=True
    )
    account_license = ResourceRelatedField(
        model=AccountLicense,
        read_only=True,
        many=True
    )

    class Meta:
        model = Account
        fields = '__all__'

    class JSONAPIMeta:
        included_resources = ['account_account_users', 'account_license']
```
@jking6884 Most likely this is the same issue you are facing then this one. Best try version DJA 4.1.0 for now till this issue has been addressed.

As a note for Django 3.2 support there were no changes needed so DJA 4.1.0 should also run with the newest Django version.

Resolving patch:
diff --git a/example/serializers.py b/example/serializers.py
--- a/example/serializers.py
+++ b/example/serializers.py
@@ -321,6 +321,9 @@ class Meta:
         # fields = ('entry', 'body', 'author',)
         meta_fields = ("modified_days_ago",)
 
+    class JSONAPIMeta:
+        included_resources = ("writer",)
+
     def get_modified_days_ago(self, obj):
         return (datetime.now() - obj.modified_at).days
 
diff --git a/rest_framework_json_api/serializers.py b/rest_framework_json_api/serializers.py
--- a/rest_framework_json_api/serializers.py
+++ b/rest_framework_json_api/serializers.py
@@ -137,7 +137,7 @@ def validate_path(serializer_class, field_path, path):
                 validate_path(this_included_serializer, new_included_field_path, path)
 
         if request and view:
-            included_resources = get_included_resources(request, self)
+            included_resources = get_included_resources(request)
             for included_field_name in included_resources:
                 included_field_path = included_field_name.split(".")
                 if "related_field" in view.kwargs:


Test patch:
diff --git a/example/tests/test_serializers.py b/example/tests/test_serializers.py
--- a/example/tests/test_serializers.py
+++ b/example/tests/test_serializers.py
@@ -198,7 +198,25 @@ def test_model_serializer_with_implicit_fields(self, comment, client):
                 "meta": {
                     "modifiedDaysAgo": (datetime.now() - comment.modified_at).days
                 },
-            }
+            },
+            "included": [
+                {
+                    "attributes": {
+                        "email": comment.author.email,
+                        "name": comment.author.name,
+                    },
+                    "id": str(comment.author.pk),
+                    "relationships": {
+                        "bio": {
+                            "data": {
+                                "id": str(comment.author.bio.pk),
+                                "type": "authorBios",
+                            }
+                        }
+                    },
+                    "type": "writers",
+                }
+            ],
         }
 
         response = client.get(reverse("comment-detail", kwargs={"pk": comment.pk}))