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

On update URI::InvalidURIError: URI must be ascii only #62

Open
luckyraul opened this issue Nov 18, 2015 · 27 comments
Open

On update URI::InvalidURIError: URI must be ascii only #62

luckyraul opened this issue Nov 18, 2015 · 27 comments
Assignees

Comments

@luckyraul
Copy link

conn = OData::Service.new "same_ip/hamster/odata/standard.odata"
conn.Document_СчетНаОплатуПокупателю
results = conn.execute
doc = results.first
doc.Комментарий = 'ruby update'

conn.update_object(doc)
result = conn.save_changes
puts "Was updated? #{result}"
@visoft visoft self-assigned this Nov 18, 2015
visoft added a commit that referenced this issue Nov 18, 2015
@visoft
Copy link
Owner

visoft commented Nov 18, 2015

Try the develop branch. I believe I fixed this.

@luckyraul
Copy link
Author

Uri error is gone, however

OData::ServiceError: XML parsing error:  - [1,1]
Fatal error: 
Document is empty

@visoft
Copy link
Owner

visoft commented Nov 18, 2015

I got that too, I figured I didn't have access to update your entities.

I'll look into this.

@luckyraul
Copy link
Author

What was the server answer? This service is not our application, just some vendor server software, so there can be some restrictions on editing, which I can't predict. If you find some restrictions responses - I can look in configuration.

@visoft
Copy link
Owner

visoft commented Nov 18, 2015

Here's the raw error:

<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code>-1</m:code>
  <m:message>XML parsing error:  - [1,1]
Fatal error: 
Document is empty
</m:message>
</m:error>

I can confirm the document is being sent over as JSON to the server with the proper Content-Type of application/json. ruby_odata receives XML and sends JSON, so I wonder if your server doesn't support JSON given that it looks like it's trying to parse XML?

@luckyraul
Copy link
Author

Yeah. As far as I am concerned it does not support json yet.

@luckyraul
Copy link
Author

I updated service. So It you want json answer you should request with header Accept: application/json or parameter ?$format=json in query mode.

@luckyraul
Copy link
Author

I dumped http and found that library use always "accept xml"

@visoft
Copy link
Owner

visoft commented Nov 19, 2015

Yes, it always accepts XML, but when it sends out say an update, it's content-type is set to application/json

@visoft
Copy link
Owner

visoft commented Nov 19, 2015

ruby_odata doesn't want JSON back (Accept) otherwise I'd have to have 2 different parsers

@luckyraul
Copy link
Author

here said to use PATCH method http://www.odata.org/getting-started/basic-tutorial/

@visoft
Copy link
Owner

visoft commented Nov 19, 2015

The OData services SHOULD support PATCH as the preferred means of updating an entity. But also services MAY additionally support PUT.

ruby_odata uses a PUT to send over the updates since it's updating the whole entity, not just pieces of it (which is what PATCHshould be used for).

@luckyraul
Copy link
Author

I've checked my issue and added ?$format=json to url and got error answer

{
"odata.error": {
"code": "4",
"message": {
"lang": "ru",
"value": "ВозвратнаяТара"
}
}

@luckyraul
Copy link
Author

Can you tell me how can I use xml for saving?

@visoft
Copy link
Owner

visoft commented Dec 6, 2015

It would require rewriting the save logic

@luckyraul
Copy link
Author

I spent some time looking in your's code. Implementing XML saving will be a huge amount of work.
Now I am trying now use json saving with $format=json parameter

this patch sample from documentation

PATCH http://host/base/odata/standard.odata/Catalog_Магазины(guid'value')?$format=json HTTP/1.1
Host: host
Connection: keep-alive
Accept: application/json
Content-Length: 638
{
    "odata.metadata": "http://host/base/odata/standard.odata/$metadata#Catalog_Магазины/@Element",
    "Description": "Новое описание магазина",
    "ТорговыеЗалы@odata.type" : "Collection(StandardODATA.Catalog_Магазины_ТорговыеЗалы_RowType)"
    "ТорговыеЗалы": [
        {
            "LineNumber": "1",
            "Название": "Синий зал",
            "Площадь": 56,
            "ДатаОткрытия": "2015-01-01T00:00:00"
    },
    {
            "LineNumber": "2",
            "Название": "Красный зал",
            "Площадь": 56,
            "ДатаОткрытия": "2015-06-13T11:45:41"
    }
    ]
}

In my case ruby is sending

"ВозвратнаяТара": {
    "__metadata": {
      "type": "Collection(StandardODATA.Document_СчетНаОплатуПокупателю_ВозвратнаяТара_RowType)"
    },
    "results": [

    ]
  },
  "УдалитьУслуги": {
    "__metadata": {
      "type": "Collection(StandardODATA.Document_СчетНаОплатуПокупателю_УдалитьУслуги_RowType)"
    },
    "results": [

    ]
  }

and server responded error

{
  "odata.error": {
    "code": "4",
    "message": {
      "lang": "ru",
      "value": "ВозвратнаяТара"
    }
  }
}

which means that problem is in the Collections.
Error 4 means - Invalid property value

@luckyraul
Copy link
Author

Do you have any comments?

@visoft
Copy link
Owner

visoft commented Dec 11, 2015

Are you changing anything before saving? The empy results collection seems like nothing has changed.

@visoft
Copy link
Owner

visoft commented Dec 11, 2015

Also, the fix I put into develop to fix the ASCII problem, doesn't work properly (failed tests), so I need to revisit that problem.

@luckyraul
Copy link
Author

doc.Комментарий = 'ruby update'

I trying to point to the difference beetween '__metadata' inside collection object and property "[email protected]"

@luckyraul
Copy link
Author

Let me check

@visoft
Copy link
Owner

visoft commented Dec 11, 2015

Do you know the version of your OData service?

@luckyraul
Copy link
Author

in metadata - v3

@luckyraul
Copy link
Author

I've looked in standard reference @odata.type is for 4, __metadata for 3

@luckyraul
Copy link
Author

in documentation they said it is 3 version. So I don't understand what's wrong with collection object

visoft added a commit that referenced this issue Dec 11, 2015
@visoft
Copy link
Owner

visoft commented Dec 11, 2015

Your service comes back with:

<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0">

While the Northwind sample comes back with:

<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0">

I'll bet something changed in v3 and because it only supports 3, the ruby_odata code must not be sending the correct thing. I'll have to look at it more closely this weekend (hopefully I will have time).

It's weird that queries still work though, I guess they didn't change that spec.

As for the ASCII problem, could you add a failing spec for this and I'll work on a fix for it? I reverted my last fix because like I said it broke some specs.

@luckyraul
Copy link
Author

There was no problem for url with our fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants