René's URL Explorer Experiment


Title: Django: invalid `VectorField` input raises `ValueError` / `DataError` instead of a validation error · Issue #171 · pgvector/pgvector-python · GitHub

Open Graph Title: Django: invalid `VectorField` input raises `ValueError` / `DataError` instead of a validation error · Issue #171 · pgvector/pgvector-python

X Title: Django: invalid `VectorField` input raises `ValueError` / `DataError` instead of a validation error · Issue #171 · pgvector/pgvector-python

Description: Hi @ankane, thanks for pgvector-python! When a VectorField gets malformed input through a ModelForm (including the admin) or a DRF ModelSerializer, the error isn't a validation error. With a non-numeric element, form.is_valid() raises Va...

Open Graph Description: Hi @ankane, thanks for pgvector-python! When a VectorField gets malformed input through a ModelForm (including the admin) or a DRF ModelSerializer, the error isn't a validation error. With a non-nu...

X Description: Hi @ankane, thanks for pgvector-python! When a VectorField gets malformed input through a ModelForm (including the admin) or a DRF ModelSerializer, the error isn't a validation error. With a no...

Opengraph URL: https://github.com/pgvector/pgvector-python/issues/171

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Django: invalid `VectorField` input raises `ValueError` / `DataError` instead of a validation error","articleBody":"Hi @ankane, thanks for pgvector-python!\n\nWhen a `VectorField` gets malformed input through a `ModelForm` (including the admin) or a DRF `ModelSerializer`, the error isn't a validation error. With a non-numeric element, `form.is_valid()` raises `ValueError`. With the wrong number of dimensions, the form or serializer is valid and `save()` raises `DataError` from Postgres. Either way the request ends in a 500 instead of a form error or a 400 response.\n\nDjango's [custom fields docs](https://docs.djangoproject.com/en/6.0/howto/custom-model-fields/#converting-values-to-python-objects) say `to_python()` should raise `ValidationError` when it can't convert a value. `VectorField.to_python` passes the string to `Vector._from_text`, and `float()` raises `ValueError`. For comparison, with `ArrayField(FloatField())` the same kind of input gives a `ValidationError`: the model field rejects `'[\"1\", \"x\"]'`, and its form field rejects `'1,2,x'` with \"Item 3 in the array did not validate\".\n\n`HalfVectorField` and `SparseVectorField` raise `ValueError` for malformed strings in the same way.\n\n### Reproduction\n\n```python\nimport django\nfrom django.conf import settings\n\nsettings.configure(\n    DATABASES={'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'pgvector_python_test'}},\n    INSTALLED_APPS=[],\n)\ndjango.setup()\n\nfrom django import forms\nfrom django.db import connection, models\nfrom pgvector.django import VectorField\nfrom rest_framework import serializers\n\n\nclass Item(models.Model):\n    embedding = VectorField(dimensions=3)\n\n    class Meta:\n        app_label = 'repro'\n\n\nwith connection.cursor() as cursor:\n    cursor.execute('CREATE EXTENSION IF NOT EXISTS vector')\n    cursor.execute('DROP TABLE IF EXISTS repro_item')\nwith connection.schema_editor() as editor:\n    editor.create_model(Item)\n\n\nclass ItemForm(forms.ModelForm):\n    class Meta:\n        model = Item\n        fields = ['embedding']\n\n\nclass ItemSerializer(serializers.ModelSerializer):\n    class Meta:\n        model = Item\n        fields = ['embedding']\n\n\ndef check(name, fn):\n    try:\n        print(f'{name}: {fn()}')\n    except Exception as e:\n        print(f'{name}: {type(e).__name__}: {e}')\n\n\ndef form(value):\n    f = ItemForm(data={'embedding': value})\n    if not f.is_valid():\n        return f'invalid {f.errors.get_json_data()}'\n    f.save()\n    return 'saved'\n\n\ndef serializer(value):\n    s = ItemSerializer(data={'embedding': value})\n    if not s.is_valid():\n        return f'invalid {s.errors}'\n    s.save()\n    return 'saved'\n\n\ncheck('form [1,2,x]', lambda: form('[1,2,x]'))\ncheck('form [1,2]', lambda: form('[1,2]'))\ncheck('serializer [1, 2, \"x\"]', lambda: serializer([1, 2, 'x']))\ncheck('serializer [1, 2]', lambda: serializer([1, 2]))\n```\n\nOutput:\n\n```text\nform [1,2,x]: ValueError: could not convert string to float: 'x'\nform [1,2]: DataError: expected 3 dimensions, not 2\nserializer [1, 2, \"x\"]: ValueError: could not convert string to float: 'x'\nserializer [1, 2]: DataError: expected 3 dimensions, not 2\n```\n\nTraceback for the first case:\n\n```text\n  .../django/forms/models.py\", line 503, in _post_clean\n  .../django/db/models/base.py\", line 1713, in full_clean\n  .../django/db/models/base.py\", line 1768, in clean_fields\n  .../django/db/models/fields/__init__.py\", line 875, in clean\n  .../pgvector/django/vector.py\", line 33, in to_python\n  .../pgvector/vector.py\", line 112, in _from_db\n  .../pgvector/vector.py\", line 88, in _from_text\nValueError: could not convert string to float: 'x'\n```\n\n### Expected\n\nAll four cases come back as invalid with a field error, and nothing reaches the database. For the dimension mismatch, the field already knows `dimensions`, so it could check the length before saving.\n\n### Versions\n\n- pgvector-python 0.5.1 (also on `master`, e0f3ac3)\n- Django 6.1.2, Django REST framework 3.18.3, Psycopg 3.3.6\n- Postgres 18.6, pgvector 0.8.7\n- Python 3.12.7\n","author":{"url":"https://github.com/ontdepart","@type":"Person","name":"ontdepart"},"datePublished":"2026-10-24T14:44:48Z","url":"https://github.com/pgvector/pgvector-python/issues/171"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:9c8ffab7-5185-5cf3-116e-a625cdf475e4
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8074:3CE0F6:9E063C:CF7942:6AFE81E9
html-safe-nonce630c09fc096a6b51a83cd680981b9cd01b7be90e13552be184abe648bc8dad09
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDc0OjNDRTBGNjo5RTA2M0M6Q0Y3OTQyOjZBRkU4MUU5IiwidmlzaXRvcl9pZCI6IjY2MTE1MzQ2ODE0MzMwODAyOTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac206dbefa1cc6372d9a676e318e4371787f5ab437062c028fc4010c285527affb
hovercard-subject-tagissue:6014134906
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pgvector/pgvector-python/171/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e30cdc664de74f12ab73f802180c00df3e584397a33b1679571e6484c58ff062/pgvector/pgvector-python/issues/171
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e30cdc664de74f12ab73f802180c00df3e584397a33b1679571e6484c58ff062/pgvector/pgvector-python/issues/171
og:image:altHi @ankane, thanks for pgvector-python! When a VectorField gets malformed input through a ModelForm (including the admin) or a DRF ModelSerializer, the error isn't a validation error. With a non-nu...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameontdepart
hostnamegithub.com
expected-hostnamegithub.com
Noneb3c0f155eafc27e60db6e254d1ffff0e072e9ab3b4018a5ee518797c19d89f86
turbo-cache-controlno-preview
go-importgithub.com/pgvector/pgvector-python git https://github.com/pgvector/pgvector-python.git
octolytics-dimension-user_id98363230
octolytics-dimension-user_loginpgvector
octolytics-dimension-repository_id376300726
octolytics-dimension-repository_nwopgvector/pgvector-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id376300726
octolytics-dimension-repository_network_root_nwopgvector/pgvector-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4a10310af51a1bfffbedc4fd81cb582acf0cb0ff
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/pgvector/pgvector-python/issues/171#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpgvector%2Fpgvector-python%2Fissues%2F171
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpgvector%2Fpgvector-python%2Fissues%2F171
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=pgvector%2Fpgvector-python
Reloadhttps://github.com/pgvector/pgvector-python/issues/171
Reloadhttps://github.com/pgvector/pgvector-python/issues/171
Reloadhttps://github.com/pgvector/pgvector-python/issues/171
pgvectorhttps://github.com/pgvector
pgvector-pythonhttps://github.com/pgvector/pgvector-python
Codehttps://github.com/pgvector/pgvector-python
Issues2 (2)https://github.com/pgvector/pgvector-python/issues
Pull requests8 (8)https://github.com/pgvector/pgvector-python/pulls
Actionshttps://github.com/pgvector/pgvector-python/actions
Security and qualityhttps://github.com/pgvector/pgvector-python/security
Insightshttps://github.com/pgvector/pgvector-python/insights
https://github.com/pgvector/pgvector-python
New issuehttps://github.com/login?return_to=https://github.com/pgvector/pgvector-python/issues/171
New issuehttps://github.com/login?return_to=https://github.com/pgvector/pgvector-python/issues/171
#172https://github.com/pgvector/pgvector-python/pull/172
Django: invalid VectorField input raises ValueError / DataError instead of a validation errorhttps://github.com/pgvector/pgvector-python/issues/171#top
#172https://github.com/pgvector/pgvector-python/pull/172
https://github.com/ontdepart
ontdeparthttps://github.com/ontdepart
on Oct 24, 2026https://github.com/pgvector/pgvector-python/issues/171#issue-6014134906
@ankanehttps://github.com/ankane
custom fields docshttps://docs.djangoproject.com/en/6.0/howto/custom-model-fields/#converting-values-to-python-objects
e0f3ac3https://github.com/pgvector/pgvector-python/commit/e0f3ac37b8f05216cd02a3e4cdd502bcbdb0539d
https://github.com/HuzaizKhalid
HuzaizKhalidhttps://github.com/HuzaizKhalid
on Nov 5, 2026https://github.com/pgvector/pgvector-python/issues/171#issuecomment-6654159037
Sign up for freehttps://github.com/signup?return_to=https://github.com/pgvector/pgvector-python/issues/171
Sign in to commenthttps://github.com/login?return_to=https://github.com/pgvector/pgvector-python/issues/171
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.