michiya / django-pyodbc-azure

Django backend for Microsoft SQL Server and Azure SQL Database using pyodbc
https://pypi.python.org/pypi/django-pyodbc-azure
BSD 3-Clause "New" or "Revised" License
321 stars 140 forks source link

Invalid precision value when inserting more than 6000 characters into TextField #148

Open albertomisail opened 6 years ago

albertomisail commented 6 years ago

OS: Windows Python version: 3.5.2 Django version: tried both with 1.11 and 2.0 Django-pyodbc-azure version: tried both with 1.11 and 2.0 (respectively)

I have a model that contains a filed "question_text" of type TextField. When I try to insert something of small length (1000 char) it works fine. However, when I try to insert something bigger (6000 char) it throws an Invalid precision value error.

Models

class Question(models.Model):
    question_text = models.TextField()
    pub_date = models.DateTimeField()

Tests

class Tests(TransactionTestCase):
    def test_text_field_fail(self):
        a = 'a'*8000
        q = Question(question_text=a, pub_date=datetime.datetime.now())
        q.save()

    def test_text_field_pass(self):
        a = 'a' * 100
        q = Question(question_text=a, pub_date=datetime.datetime.now())
        q.save()

Settings

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'HOST': '----',
        'NAME': '----',
        'USER': '----',
        'PASSWORD': '---',
        'OPTIONS': {'driver': 'ODBC Driver 13 for SQL Server',},
    }
}
stefanhdao commented 6 years ago

Can you test 4000 and 4001 characters?

albertomisail commented 6 years ago

4000 passed 4001 failed