Cannot create a polymorphic project instance in Django Rest framework JSON API example project - django

I am trying to understand how polymorphic resources work in django-rest-framework-json-api and I get the following error both on my own project and the example project provided by django-rest-framework-json-api. My models are created using django-polymorphic. The example project I am trying to run is https://github.com/django-json-api/django-rest-framework-json-api/tree/master/example.
Endpoint : localhost:8000/projects
{
"errors": [
{
"detail": "Incorrect relation type. Expected on of [artProject, researchProject], received None.",
"source": {
"pointer": "/data"
},
"status": "409"
}
]
}
Project page's form used to create a new instance doesn't have any field that I can specify the type of the Project. It only shows the topic field. So I am also wondering how I can create an Art project for instance.
In the documentation it says the type is determined by the resource_name in Meta data of either view, serializer or model. But type is none in the returned json data. It is because serializer.instance = None which is used to determine the type when force_type_resolution is set to True. It is set to True to force polymorphic serializers to resolve the type based on instance.
So I can't seem to fix this issue, maybe I am missing some configuration or there really is a bug in the code but I have no idea. Can someone please tell me how to solve this if you have come across this issue or know how to get the example app working with polymorphic resources?

I was initially trying to create instances in the browser which threw the error above and didn't let me choose child types. I tested this on Postman and specified the type and it worked. I had the impression that I could even create an instance of Project as well (Parent instance itself, not a child instance) but as error message clearly says, I can't.

Related

Methods missing for instance of Great Expectation validator

I have recently tried to use Great expectations in a data creation pipeline but I run into a problem with validator object.
I followed this tutorial to set things up: https://docs.greatexpectations.io/docs/deployment_patterns/how_to_use_great_expectations_in_databricks/
I created my validator instance with following:
validator = context.get_validator(
batch_request=batch_request_1,
expectation_suite_name=expectation_suite_name,
)
Then I tried to set some expectations manually or with profiler but got those errors:
validator.expect_column_values_to_not_be_null(column="col")
AttributeError: 'Validator' object has no attribute 'expect_column_values_to_not_be_null'
profiler = UserConfigurableProfiler(profile_dataset=validator)
AttributeError: 'Validator' object has no attribute 'expect_column_values_to_be_in_type_list'
It looks like my instance does not have those methods and indeed when I hit tab to check what options I have with validator there are many other expect_column_.... But none of those 2.
Can you please advise me how to fix my validator object?

"Type" used as keyword raising an exception in RSpec but not in production or development environments

I'm working on a large web app that uses "type" as a column in the database for many of the tables. I understand that the word "type" is a keyword in Ruby, and should not be used as columns. However, why is it that I can still run the web app on my local server just fine, and that there aren't any apparent problems in the production environment? Will using "type" as a column potentially cause any trouble in the future?
This behavior is even more confusing because it does cause my RSpec feature tests to fail when creating a video (one of the resources) and then redirecting to the show view. (Note that the video as attributes that have associations with several of the tables which have "type" as a column).
This is the error message that is raised :
"The single-table inheritance mechanism failed to locate the subclass:
'reference'. This error is raised because the column
'type' is reserved for storing the class in case of
inheritance. Please rename this column if you didn't intend it to
be used for storing the inheritance class or overwrite
Tag.inheritance_column to use another column for that information."
(Pulled from the HTML generated and displayed by print page.body)
Why would this exception to raised in my test specs but not in the development or production environments? (I'm in charge of putting together test specs, so you have in your device on ways to get around this error, that would be helpful too!)
Notes on my configuration:
I'm using Ruby 2.1.2 and rails 4.1.1
Using capybara, factory girl, and capybara-WebKit as the web driver
As it turns out, there was an explicit type column in the schema but it was pulled from the subclass of the resource. The reason that RSpec had a problem is that I was trying to define the type column without making it a subclass. The solution was to use subclassed notation when inputting data into the type. In my case, this means the string in the type column needed to be put in as: "Tags::Reference" rather than "reference".

Enable nestRemoting for more than 2 levels (for nested queries)

My question is basically is, how can I enable nestRemoting (nested queries for related models) for more than 3 related models?
Currently I am working with 4 related models and would like to be able to do nested queries all the way up or down, and right now I am only able to do so for 3 models (i.e. 2 levels up and 2 levels down).
What works:
So for example, I have my Account model which is the root of everything, i.e. all other models eventually lead to an Account) and then I have let's say Projects, Folders then Photos as leaves.
I already configured my relations and it works perfectly fine, e.g.
Account hasMany Projects
Project hasMany Folders
Folder hasMany Photos
and the other way around as well:
Photo belongsTo Folder
Folder belongsTo Project
Project belongsTo Account
and finally in my code I added:
// Configure one way of the relation
Account.nestRemoting('projects');
Project.nestRemoting('folders');
Folder.nestRemoting('photos')
// Configure the other way of the relation
Photo.nestRemoting('folder')
Folder.nestRemoting('project')
Project.nestRemoting('account');
This works wonderful and lets me do things like
/api/Accounts/<account id>/projects/<project id>/folders
To get a list of Folders that belong to that Account.
And viceversa, I am able to do the other way around:
/api/Photos/folder/project/
However:
When I try to add one more nested level to the query in either direction I get an error.
I.e. if I try to do
/api/Accounts/<account id>/projects/<project id>/folders/<folder id>/photos
or if I do
/api/Photos/folder/project/account
I get the following error:
"name": "Error",
"status": 404,
"message": "Shared class \"Account\" has no method handling GET /<uuid>/projects/<uuid>/folders/<uuid>/photos?access_token=XXXXXXXXXXXXXXX",
"statusCode": 404,
"stack": "Error: Shared class \"Account\" has no method handling GET /<uuid>/projects/<uuid>/folders/<uuid>/photos?access_token=XXXXXXXXXXXXXXX\n at restRemoteMethodNotFound (/myserver/node_modules/loopback/node_modules/strong-remoting/lib/rest-adapter.js:322:17)\n at Layer.handle [as handle_request] (/myserver/node_modules/loopback/node_modules/express/lib/router/layer.js:95:5)\n
(I replaced the actual id for for redability)
But this error is only triggered when I try to query more than 2 levels above the model (or 2 levels below).
So for example if I start one level below (e.g. at Project instead of Account):
/api/Projects/<project id>/folders/<folder id>/photos
This works fine.
Or the other way around:
/api/Folders/project/account
That tells me that the methods and everything is working as expected but there is a limit on the nesting levels.
So back to my original question, how can I add more levels to a nested query? is there anything I can config without modifying loopback's source code?
By the way, my datasource is a MongoDB instance (i.e. mongodb connector)
Thanks!
#Ivan Schwarz was right. It turns out that this is not a bug but an unsupported feature.
The details are here.
After poking around in the code, I found out that the root problem is that there is no relation defined between more than 2 levels of models so there is no way to traverse the dependency tree as it stands now.
The changes needed involve somehow traversing the relations of the related models and the relations of the latter, and so on, but right now that traversing is not coded.
The workaround is basically to define your own remote method by hand and call that instead.

Post an Object to Facebook Graph API Explorer

Trying to figure out the correct Json string to pass to my OpenGraph app. I'm using the Gigya Java SDK, but decided to eliminate some of the extra layers in testing the string.
So I'm first of all looking at the Graph API Explorer.
My POST field name is "Recipe" and the value is
{"title":"one-handed fried pies","description":"ye olde Description goeth here.","image":"http://www.recipe.com/images/one-handed-fried-pies-R094255-ss.jpg","url":"http://www.recipe.com/one-handed-fried-pies/"}
This maps exactly to the fields of the Recipe object.
However, no matter how I format the JSON, I get this exception
{
"error": {
"message": "(#3503) \"{\"title\":\"one-handed fried pies\",\"description\":\"ye olde Description goeth here.\",\"image\":\"http://www.recipe.com/images/one-handed-fried-pies-R094255-ss.jpg\",\"url\":\"http://www.recipe.com/one-handed-fried-pies/\"}\" is an invalid value for property \"recipe\" with type \"Reference\"",
"type": "OAuthException",
"code": 3503
}
}
Any thoughts?
By hacking thru, got it to work this way.
Most important... the URL as above must point to a page that has valid og: tags for the app. (You can look at the source of this page for the structure http://www.csmonitor.com/Science)
In the Graph Api Explorer,Select your Application in the top left.
Click get Access token.
Select POST.
Click on Add a field
Type the name of the object. In my case "recipe".
Type the url. In my case, I set up a live test page and deployed it.
click submit and wait for an id.
{
"id": "290473937742173"
}

SharePoint Web Services - Updating ContentType field Required property?

I've been trying to programmatically reproduce the behavior of editing a Content Type's field properties in the SharePoint site management screen and selecting the "Required" radio button with no sucess using the WSS 3.0 web service's Webs.asmx "UpdateContentType" method.
The first difficulty was the issue with the MSDN documentation that said fields should be of a FieldRef type when in fact they need to be of a Field type (reference). Adding fields and deleting fields works fine after the fix, but updating fields seems to not function at all. (It should also be noted that I followed the recommendation on the previous link to use Method="2" for updating fields but it changes nothing, and using Method values other than 1 for adding or other than 3 for deleting also function correctly).
Here's the web service call (slightly modified with strings instead of XmlNode objects for readability):
SharePointWebServices.Webs webService = new SharePointWebServices.Webs();
webService.Url = "http://mysharepointserver/site";
webService.UseDefaultCredentials = true;
webService.UpdateContentType(
#"0x01005A089D9EC8A382458FB1F6C72096D52A",
#"<ContentType />",
#"<Fields />",
#"<Fields><Method ID=""1""><Field Name=""SomeField"" ID=""{8a4803c4-6545-4a7a-804d-237eebff0ce3}"" Required=""TRUE"" Hidden=""FALSE"" ReadOnly=""FALSE"" PITarget="""" PIAttribute="""" PrimaryPIAttribute="""" Aggregation="""" Node="""" /></Method></Fields>",
#"<Fields />");
After the call, the field is still Required="FALSE".
A quick look into the stssoap.dll assembly indicates that the "Required" property is apparently ignored during the update process. Is this normal behavior? If so, what is the recommended method for programmatically changing the "Required" field from client code (not executing on the SharePoint server)?
Any help would be greatly appreciated.
I've investigated this and found the same thing. I also tried adding the attribute Cmd="Update" to the Method element without success. This example of how to use UpdateContentType was helpful too.
I don't believe you will be able to do this with the out-of-the-box SharePoint services. You've verified from looking at stssoap.dll that this doesn't appear to work correctly. Another 'client'-style option is to use RPC methods but none appear to provide functionality for content types at all.
The web services are particularly frustrating because this type of not-so-edge case regularly comes up. It is very rare that I consider using them because of the time wasting involved with their limitations.
Do you have any option of deploying custom code to the server? You could develop this functionality using the object model and wrap it in your own custom web service (there is a walkthrough here) quite easily.
Here is an example adapted from Gabe Wishnie that does what you require:
SPContentType myContentType = myWeb.ContentTypes["myContentType"];
string internalName = myContentType.Fields["fieldToUpdate"].InternalName;
myContentType.FieldLinks[internalName].Required = false;
myContentType.Update(true);
Sorry this isn't more helpful but it's a common story when using the WSS 3.0 / SharePoint 2007 web services.