question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inflection ignored in lookup by RelationshipView

See original GitHub issue

I did a quick search and didn’t find a similar issue, but I apologize if I missed one on this topic. And, maybe this is an enhancement request rather than a bug report. It is an inconsistency in type names between the url and rendered document.

For an api view of a model I have eg http://localhost/api/customer-accounts/ where the relationship type (lets just call it relationship-name) is inflected correctly according to the setting JSON_API_FORMAT_TYPES (dasherized, in this case)

{
    "links": {
        "first": "http://localhost/api/customer-accounts/?page%5Bnumber%5D=1",
        "last": "http://localhost/api/customer-accounts/?page%5Bnumber%5D=1",
        "next": null,
        "prev": null
    },
    "data": [
        {
            "type": "customer-accounts",
            "id": "1",
            "attributes": {
                "account-id": 1,
                "account": "1234",
                "insert-ts": "2020-05-20T20:42:52.895506Z",
                "update-ts": "2020-05-20T20:42:52.895643Z"
            },
            "relationships": {
                "relationship-name": {
                    "data": {
                        "type": "relationship-name",
                        "id": "1"
                    }
                }
            }
        }
    ],
    "meta": {
        "pagination": {
            "page": 1,
            "pages": 1,
            "count": 1
        }
    }
}

Then I go to eg http://localhost/api/customer-accounts/1/relationships/relationship-name/ and get a 404. Instead, I find the relationship at http://localhost/api/customer-accounts/1/relationships/relationship_name/ which looks like:

{
    "data": {
        "type": "relationship-name",
        "id": "1"
    }
}

The rendered document has the correctly inflected type, which doesn’t match the url.

I am working around this for now using field name mapping in RelationshipView

field_name_mapping = {
        'relationship-name': 'relationship_name'
    }

Could RelationshipView pass relationship-name through the inflector first to get it back to the internal python (underscore) convention?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sliverccommented, Dec 6, 2020

When the feature of formatting is being used DJA assumes that the field names are named with the Python convention of underscoring. This is currently done in the parser so you can do it here too.

1reaction
sliverccommented, Dec 3, 2020

Thanks @platinumazure that you are willing to work on this issue.

I think inflection for relationship view should be the default as I consider this issue a bug. As this is not a minor change it is certainly good to implement it backwards compatible. I think easiest would be to implement a setting where inflection of relationship view can be turned on. However when the setting is off and someone uses the relationship view a deprecation warning can be raised.

In PR https://github.com/django-json-api/django-rest-framework-json-api/pull/776 a similar approach has been taken so you can find how to introduce a new setting and how to raise a deprecation warning.

Let me know if you need any more hinters.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring relationships when using lookup value or alternative
The ideal is to use lookupvalue but ignore relationships. The first thing I tried was lookupvalue but found it worked only on finding...
Read more >
Video: Create relationships with the Lookup Wizard
Try it! The Lookup Wizard establishes a relationship between tables. It creates a foreign key that refers back to the primary key of...
Read more >
Privacy and Property Rights – an emerging inflection point in the ...
We're collectively ignoring the wisdom of the Library Bill of Rights. Today, our most personal information has value – by some estimates around...
Read more >
Analysis of research intensity on infectious disease by ... - NCBI
However, neglected tropical diseases, such as Chagas disease and ... correlation under the double logarithmic linear relationship was 0.2, ...
Read more >
Slocum Masterdata 06.37
see secs_after_data_transmission() # hydro_smp sensor: dhs_valid(bool) 0 ... depth vs neutral buoyancy lookup table sensor: x_hover_ballast_shallow(cc) 0.0 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found