gs1 / GS1_DigitalLink_Resolver_CE

The GS1 DigitalLink Resolver Community Edition
Apache License 2.0
38 stars 22 forks source link

V3 Resolver returning linkset json instead of default link #97

Closed ablears closed 1 month ago

ablears commented 1 month ago

Hi, I upgraded to 3 from 2.6.

Resolver links that were working OK, such as https://id.ibn.link/01/00701197903555 now do not resolve to the default link. They instead show a linkset json response, presumably because of the change to how default links are handled.

{"linkset": [{"href": "https://future-products.com.au/vivafizz-naturale/", "title": "VivaFizz Naturale", "type": "text/html", "hreflang": ["en"]}, {"href": "https://future-products.com.au/vivafizz-naturale-br/", "title": "VivaFizz Naturale", "type": "text/html", "hreflang": ["pt"]}]}

Given the request is from a browser with EN language, why is it not resolving to the EN link? Is there a new syntax for retrieving the default link?

Here's what our UI sends in this example: [{"anchor":"/01/00701197903555","itemDescription":"<p>VivaFizz Naturale: A Refreshing Twist on Health and Flavour</p>\r\n","defaultLinktype":"gs1:pip","links":[{"linktype":"gs1:pip","hreflang":["en"],"type":"text/html","title":"VivaFizz Naturale","href":"https://future-products.com.au/vivafizz-naturale/"},{"linktype":"gs1:pip","hreflang":["pt"],"type":"text/html","title":"VivaFizz Naturale","href":"https://future-products.com.au/vivafizz-naturale-br/"},{"linktype":"gs1:faqs","hreflang":["en"],"type":"text/html","title":"VivaFizz Naturale","href":"https://future-products.com.au/faq/"},{"linktype":"gs1:sustainabilityInfo","hreflang":["en"],"type":"text/html","title":"VivaFizz Naturale","href":"https://future-products.com.au/nurturing-nature-sustaining-flavour/"},{"linktype":"gs1:homepage","hreflang":["en"],"type":"text/html","title":"VivaFizz Naturale","href":"https://future-products.com.au/about-us/"}]}]"

My expectation is that https://id.ibn.link/01/00701197903555 will resolve to https://future-products.com.au/vivafizz-naturale/ or https://future-products.com.au/vivafizz-naturale-br/ if the request comes from a browser with Portuguese language set.

Here is what I see in the resolver logs:

GS1 identifiers only: /01/00701197903555 identifier: /01/00701197903555 read_document: No qualifiers found in the document DEBUG Can we match on all three contexts?: ['en-US', 'en;q=0.5'] None ['text/html', 'application/xhtml+xml', 'application/xml;q=0.9', 'image/avif', 'image/webp', 'image/png', 'image/svg+xml', '/;q=0.8'] DEBUG Can we match on accept_language_list and context?: ['en-US', 'en;q=0.5'] None DEBUG Can we match on accept_language_list and media_types_list?: ['en-US', 'en;q=0.5'] ['text/html', 'application/xhtml+xml', 'application/xml;q=0.9', 'image/avif', 'image/webp', 'image/png', 'image/svg+xml', '/;q=0.8'] DEBUG Can we match on context and media_types_list?: None ['text/html', 'application/xhtml+xml', 'application/xml;q=0.9', 'image/avif', 'image/webp', 'image/png', 'image/svg+xml', '/;q=0.8'] DEBUG Can we match on accept_language_list?: ['en-US', 'en;q=0.5'] DEBUG Can we match on context?: None DEBUG Can we match on media_types_list?: ['text/html', 'application/xhtml+xml', 'application/xml;q=0.9', 'image/avif', 'image/webp', 'image/png', 'image/svg+xml', '/;q=0.8'] DEBUG Found a match on media_types_list DEBUG Found a match on media_types_list Accept header: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/png,image/svg+xml,/;q=0.8 INFO:werkzeug:172.21.0.5 - - [29/Jul/2024 03:50:47] "GET /api/01/00701197903555 HTTP/1.0" 300 - COMPRESSED LINK: favicon.ico DEBUG => stdout: b'{\n "SUCCESS": false\n}\n' DEBUG ==> decompress_result: {'SUCCESS': False} WARNING:web_namespace:Error getting document 'error' ERROR:init:Exception on /api/favicon.ico [GET] Traceback (most recent call last): File "/app/web_namespace.py", line 83, in get return {'error': decompress_result['error']}, 400 KeyError: 'error'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 867, in full_dispatch_request rv = self.dispatch_request() File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 852, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(view_args) File "/usr/local/lib/python3.10/site-packages/flask_restx/api.py", line 402, in wrapper resp = resource(args, kwargs) File "/usr/local/lib/python3.10/site-packages/flask/views.py", line 109, in view return current_app.ensure_sync(self.dispatch_request)(kwargs) File "/usr/local/lib/python3.10/site-packages/flask_restx/resource.py", line 41, in dispatch_request resp = meth(args, kwargs) File "/app/web_namespace.py", line 87, in get abort(500, description="Error getting document") File "/usr/local/lib/python3.10/site-packages/flask/helpers.py", line 274, in abort current_app.aborter(code, *args, *kwargs) File "/usr/local/lib/python3.10/site-packages/werkzeug/exceptions.py", line 863, in call raise self.mapping[code](args, **kwargs) werkzeug.exceptions.InternalServerError: 500 Internal Server Error: Error getting document INFO:werkzeug:172.21.0.5 - - [29/Jul/2024 03:50:47] "GET /api/favicon.ico HTTP/1.0" 500 -

nicklansley commented 1 month ago

Hi @ablears thanks for sending this - I will see what has happened and fix today.

Can you confirm that this is the payload you sent into the POST /api/new call?

[
    {
        "anchor": "/01/00701197903555",
        "itemDescription": "VivaFizz Naturale: A Refreshing Twist on Health and Flavour",
        "defaultLinktype": "gs1:pip",
        "links": [
            {
                "linktype": "gs1:pip",
                "hreflang": [
                    "en"
                ],
                "type": "text/html",
                "title": "VivaFizz Naturale",
                "href": "https://future-products.com.au/vivafizz-naturale/"
            },
            {
                "linktype": "gs1:pip",
                "hreflang": [
                    "pt"
                ],
                "type": "text/html",
                "title": "VivaFizz Naturale",
                "href": "https://future-products.com.au/vivafizz-naturale-br/"
            },
            {
                "linktype": "gs1:faqs",
                "hreflang": [
                    "en"
                ],
                "type": "text/html",
                "title": "VivaFizz Naturale",
                "href": "https://future-products.com.au/faq/"
            },
            {
                "linktype": "gs1:sustainabilityInfo",
                "hreflang": [
                    "en"
                ],
                "type": "text/html",
                "title": "VivaFizz Naturale",
                "href": "https://future-products.com.au/nurturing-nature-sustaining-flavour/"
            },
            {
                "linktype": "gs1:homepage",
                "hreflang": [
                    "en"
                ],
                "type": "text/html",
                "title": "VivaFizz Naturale",
                "href": "https://future-products.com.au/about-us/"
            }
        ]
    }
]
nicklansley commented 1 month ago

HI @ablears - Your test revealed that the code was not removing the ';q=' sub-part of the language so that it was not getting always getting a language match when a web browser was used that includes the q= in its list. This is now fixed and unveiled another bug which was going through the URL list and seeing if there was a language match, rather than going through the languages and see if there is a URL list match. I've updated the tests in setup_test.py to reflect this test for the correct langauge. So thank you! And please test to make sure it works for you before I close this issue.

ablears commented 1 month ago

Hi @nicklansley, this is confirmed working. Thank you for your time.