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

Hypothesis ignores max_items and min_items for conlist #2875

Closed
3 tasks done
mdavis-xyz opened this issue Jun 3, 2021 · 2 comments
Closed
3 tasks done

Hypothesis ignores max_items and min_items for conlist #2875

mdavis-xyz opened this issue Jun 3, 2021 · 2 comments
Assignees
Labels
bug V1 Bug related to Pydantic V1.X Feedback Wanted hypothesis related to Hypothesis testing library

Comments

@mdavis-xyz
Copy link
Contributor

mdavis-xyz commented Jun 3, 2021

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this is a bug

debug info

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

             pydantic version: 1.8.2
            pydantic compiled: False
                 install path: /home/ec2-user/environment/scratch/pydantic/pydantic/pydantic
               python version: 3.8.7 (default, Jun  2 2021, 12:58:26)  [GCC 7.3.1 20180712 (Red Hat 7.3.1-12)]
                     platform: Linux-4.14.232-176.381.amzn2.x86_64-x86_64-with-glibc2.26
     optional deps. installed: ['devtools', 'dotenv', 'email-validator', 'typing-extensions']

MWE

import typing
from hypothesis import given, strategies as st
from pydantic import BaseModel, conlist

class Model(BaseModel):
    x: conlist(int, min_items=1)
    
@given(st.builds(Model))
def test_property(instance):
    assert isinstance(instance, Model)
    assert len(instance.x) >= 1
    
test_property()

The expected behavior is that the script passes. Hypothesis does not generate an empty list.

Actual behavior is that hypothesis generates an empty list.

Traceback (most recent call last):
  File "mwe.py", line 13, in <module>
    test_property()
  File "mwe.py", line 10, in test_property
    def test_property(instance):
  File "/home/ec2-user/.local/lib/python3.8/site-packages/hypothesis/core.py", line 1169, in wrapped_test
    raise the_error_hypothesis_found
  File "pydantic/main.py", line 400, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for Model
x
  ensure this value has at least 1 items (type=value_error.list.min_items; limit_value=1)

This issue is similar to #2473

Solution

A fix would look similar to #2442

@lig
Copy link
Contributor

lig commented Aug 10, 2023

@mdavis-xyz thank you for the bug report. Could you please confirm that the bug is still relevant in Pydantic v2?

@sydney-runkle
Copy link
Member

We’re no longer actively developing Pydantic V1 (although it will continue to receive security fixes for the next year or so), so we’re closing issues solely related to V1. If you really think this shouldn’t be closed, please comment or create a new issue 🚀.

@sydney-runkle sydney-runkle closed this as not planned Won't fix, can't repro, duplicate, stale Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X Feedback Wanted hypothesis related to Hypothesis testing library
Projects
None yet
Development

No branches or pull requests

4 participants