Skip to content

Model.objects.all() does not convert types in primary keys #147

Open

Description

@jacebrowning

See this test reproducing the failure:

def test_values_are_filled_from_disk(expect):
InventoryItem.objects.get_or_create(42, "Things", 0.99)
items = list(InventoryItem.objects.all())
expect(items[0]) == InventoryItem(42, "Things", 0.99)

Activity

  1. nielslerches commented on Sep 19, 2022

    @nielslerches

    Hi,

    Is this issue still relevant?

    If so, I'd like to take a crack at solving the issue, as I have a potential use case for this feature.

  2. jacebrowning commented on Sep 19, 2022

    @jacebrowning
    OwnerAuthor

    @nielslerches yes, it's still an issue. You can confirm that by removing the xfail marker to see the test fail.

    Let me know if you have any more questions!

  3. added a commit that references this issue on Sep 20, 2022
  4. Yuren0312 commented on Oct 18, 2026

    @Yuren0312

    I can confirm this is still an issue on current main — Model.objects.all() extracts path fields (like the primary key) from the filename as strings, and because those fields aren't stored in the file contents, they never pass through the field's converter in Mapper.load() (which deliberately excludes pattern fields).

    I've opened #501 with a fix: all() now coerces the path-derived values to their declared types via the existing map_type() machinery before calling get(). I also removed the xfail marker on test_values_are_filled_from_disk, which now passes.

    Verification: pytest tests/ is 128 passed / 1 skipped / 4 xfailed (remaining xfails are unrelated pre-existing issues), and mypy/black/isort/pylint/pydocstyle all pass. Happy to adjust if you'd prefer a different approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions