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

Error when using UUIDField as EAV2_PRIMARY_KEY_FIELD value #478

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
413cdf7
add uuid configuration for id generation of eav models
mathiasag7 Sep 6, 2023
8977495
add charfield possibility to eav id models field
mathiasag7 Sep 6, 2023
de7fb79
feat: natural key handler added to models except value model
mathiasag7 Sep 6, 2023
a73e327
feat: natural key handler added to value model
mathiasag7 Sep 6, 2023
6a01f16
Update CHANGELOG.md
mathiasag7 Sep 6, 2023
4be9a24
Update pyproject.toml
mathiasag7 Sep 6, 2023
832d4f3
fix: get attribute for value natural key function
mathiasag7 Sep 7, 2023
ac3c60b
Merge branch 'master' of github.com:mathiasag7/django-eav2-uuid
mathiasag7 Sep 7, 2023
7ebfb85
update package log
mathiasag7 Sep 7, 2023
ce2b606
fix: error on attribute creation
mathiasag7 Sep 7, 2023
dffbe60
Update README.md
mathiasag7 Oct 5, 2023
2c69da6
readme updated
mathiasag7 Oct 5, 2023
e275a7f
readme updated
mathiasag7 Oct 5, 2023
0aa172c
changelog updated
mathiasag7 Oct 6, 2023
33f6279
feat: natural key for serialization and UUIDField possibility for pk …
mathiasag7 Oct 6, 2023
f342f3c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 6, 2023
6e90e9c
test: test_attribute errors corrected on AutoField
mathiasag7 Oct 13, 2023
06e8cd5
Merge branch 'master' of github.com:mathiasag7/django-eav2-uuid
mathiasag7 Oct 13, 2023
13e5e99
Merge branch 'jazzband:master' into master
mathiasag7 Oct 13, 2023
668dcab
test: pytest.ini file added
mathiasag7 Oct 13, 2023
011965f
Merge branch 'master' of github.com:mathiasag7/django-eav2-uuid
mathiasag7 Oct 13, 2023
e64425d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2023
0d705d9
test: pyproject.toml updated"
mathiasag7 Oct 13, 2023
0000e26
migration file created
mathiasag7 Oct 13, 2023
7a00e04
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 13, 2023
d26f61a
test updated
mathiasag7 Oct 13, 2023
8bf3fee
Merge branch 'master' of github.com:mathiasag7/django-eav2-uuid
mathiasag7 Oct 13, 2023
4ef7f7a
test updated
mathiasag7 Oct 13, 2023
9407982
revert changes
mathiasag7 Oct 16, 2023
1d70d73
convert tests to pytest
Dresdn Oct 24, 2023
f7cd292
remove test cehcking for ValueError
Dresdn Oct 24, 2023
db893d3
feat: test_natural_keys implemented
mathiasag7 Oct 25, 2023
43365cd
Merge branch 'master' of github.com:mathiasag7/django-eav2-uuid
mathiasag7 Oct 25, 2023
b0c2b50
set charfield as default pk to avoid errors
mathiasag7 Dec 4, 2023
5c0b0d6
changelog updated
mathiasag7 Dec 4, 2023
2f1957f
fix: error in migration files
mathiasag7 Dec 20, 2023
ae01a4c
Merge branch 'jazzband:master' into master
mathiasag7 Mar 8, 2024
1d6f15d
Merge branch 'jazzband:master' into master
mathiasag7 Mar 15, 2024
2ff9292
tests + migration file updated
mathiasag7 Mar 22, 2024
3b8d28c
tests + migration file updated
mathiasag7 Mar 22, 2024
4c6ceed
tests + migration file updated
mathiasag7 Mar 22, 2024
08a2699
tests + migration file updated
mathiasag7 Mar 22, 2024
d35289f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 22, 2024
b2f8124
tests + migration file updated
mathiasag7 Mar 25, 2024
b011b1b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Mar 25, 2024
7fb9e7c
tests + migration file updated
mathiasag7 Mar 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Version History
# Version History

We follow [Semantic Versions](https://semver.org/) starting at the `0.14.0` release.

Expand All @@ -13,6 +14,13 @@ We follow [Semantic Versions](https://semver.org/) starting at the `0.14.0` rele
- Enhance BaseEntityAdmin by @Dresdn in https://github.com/jazzband/django-eav2/pull/541
- Remove support for Django < 3.2 and Python < 3.8 by @Dresdn in https://github.com/jazzband/django-eav2/pull/542

## 1.5.1 (2023-12-04)

### Bug Fixes

- Fixes errors in migrations [#406](https://github.com/jazzband/django-eav2/issues/406)


## 1.5.0 (2023-11-08)

### Bug Fixes
Expand Down
27 changes: 26 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) and follow the [guidelines](https://jazzband.co/about/guidelines).

# Contributing

We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's:

- Reporting a bug
Expand All @@ -23,6 +24,19 @@ poetry install

To activate your `virtualenv` run `poetry shell`.

## Configuration

Set EAV2_PRIMARY_KEY_FIELD value to `django.db.models.UUIDField` or `django.db.models.BigAutoField` in your settings.

```python
EAV2_PRIMARY_KEY_FIELD = "django.db.models.UUIDField" # as example
```

and run
```bash
python manage.py makemigrations
python manage.py migrate
```

## Tests

Expand All @@ -34,10 +48,20 @@ To run all tests:
pytest
```

## Cleanup

At the end of the test, ensure that you delete the migration file created by the EAV2_PRIMARY_KEY_FIELD change. Additionally, verify that the migration files are clean and reset the value to django.db.models.CharField in your settings.

```python
EAV2_PRIMARY_KEY_FIELD = "django.db.models.CharField"
```

## We develop with Github

We use github to host code, to track issues and feature requests, as well as accept pull requests.

### We use [Github Flow](https://guides.github.com/introduction/flow/index.html), so all code changes from community happen through pull requests

Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:

1. Fork the repo and create your branch from `master`.
Expand All @@ -48,11 +72,12 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu
6. Describe the pull request using [this](https://github.com/jazzband/django-eav2/blob/master/PULL_REQUEST_TEMPLATE.md) template.

### Any contributions you make will be under the GNU Lesser General Public License v3.0

In short, when you submit code changes, your submissions are understood to be under the same [LGPLv3](https://choosealicense.com/licenses/lgpl-3.0/) that covers the project. Feel free to contact the maintainers if that's a concern.

### Report bugs using Github's [issues](https://github.com/jazzband/django-eav2/issues)
We use GitHub issues to track public bugs. Report a bug by opening a new issue. Use [this](https://github.com/jazzband/django-eav2/blob/master/.github/ISSUE_TEMPLATE/bug_report.md) template to describe your reports.

We use GitHub issues to track public bugs. Report a bug by opening a new issue. Use [this](https://github.com/jazzband/django-eav2/blob/master/.github/ISSUE_TEMPLATE/bug_report.md) template to describe your reports.

### Use a consistent coding style

Expand Down
27 changes: 10 additions & 17 deletions eav/migrations/0010_dynamic_pk_type_for_models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 4.2.11 on 2024-03-26 09:01

from django.db import migrations, models


class Migration(migrations.Migration):
"""Migration to use BigAutoField as default for all models."""

dependencies = [
('eav', '0009_enchance_naming'),
Expand All @@ -12,37 +13,29 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='attribute',
name='id',
field=models.BigAutoField(
editable=False,
primary_key=True,
serialize=False,
field=models.CharField(
editable=False, max_length=40, primary_key=True, serialize=False
),
),
migrations.AlterField(
model_name='enumgroup',
name='id',
field=models.BigAutoField(
editable=False,
primary_key=True,
serialize=False,
field=models.CharField(
editable=False, max_length=40, primary_key=True, serialize=False
),
),
migrations.AlterField(
model_name='enumvalue',
name='id',
field=models.BigAutoField(
editable=False,
primary_key=True,
serialize=False,
field=models.CharField(
editable=False, max_length=40, primary_key=True, serialize=False
),
),
migrations.AlterField(
model_name='value',
name='id',
field=models.BigAutoField(
editable=False,
primary_key=True,
serialize=False,
field=models.CharField(
editable=False, max_length=40, primary_key=True, serialize=False
),
),
]
3 changes: 1 addition & 2 deletions eav/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
from functools import wraps
from itertools import count

from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Case, IntegerField, Q, When
from django.db.models.query import QuerySet
from django.db.utils import NotSupportedError
from django.db.models import Subquery

from eav.models import Attribute, EnumValue, Value

Expand Down
61 changes: 30 additions & 31 deletions test_project/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import uuid
# Generated by Django 4.2.11 on 2024-03-22 12:04

from django.db import migrations, models

from test_project.models import MAX_CHARFIELD_LEN
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):
"""Initial migration for test_project."""

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name='Doctor',
fields=[
(
'id',
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
('name', models.CharField(max_length=254)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='ExampleMetaclassModel',
fields=[
Expand All @@ -25,7 +42,7 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('name', models.CharField(max_length=254)),
],
options={
'abstract': False,
Expand All @@ -43,7 +60,7 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('name', models.CharField(max_length=254)),
],
options={
'abstract': False,
Expand All @@ -61,7 +78,7 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('name', models.CharField(max_length=254)),
],
options={
'abstract': False,
Expand All @@ -79,14 +96,14 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('email', models.EmailField(blank=True, max_length=MAX_CHARFIELD_LEN)),
('name', models.CharField(max_length=254)),
('email', models.EmailField(blank=True, max_length=254)),
(
'example',
models.ForeignKey(
blank=True,
null=True,
on_delete=models.deletion.PROTECT,
on_delete=django.db.models.deletion.PROTECT,
to='test_project.examplemodel',
),
),
Expand All @@ -107,8 +124,8 @@ class Migration(migrations.Migration):
verbose_name='ID',
),
),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
('models', models.ManyToManyField(to='test_project.ExampleModel')),
('name', models.CharField(max_length=254)),
('models', models.ManyToManyField(to='test_project.examplemodel')),
],
options={
'abstract': False,
Expand All @@ -130,7 +147,7 @@ class Migration(migrations.Migration):
(
'patient',
models.ForeignKey(
on_delete=models.deletion.PROTECT,
on_delete=django.db.models.deletion.PROTECT,
to='test_project.patient',
),
),
Expand All @@ -139,22 +156,4 @@ class Migration(migrations.Migration):
'abstract': False,
},
),
migrations.CreateModel(
name='Doctor',
fields=[
(
'id',
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
('name', models.CharField(max_length=MAX_CHARFIELD_LEN)),
],
options={
'abstract': False,
},
),
]
9 changes: 2 additions & 7 deletions test_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,11 @@
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
},
}
DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}


DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
EAV2_PRIMARY_KEY_FIELD = 'django.db.models.AutoField'
EAV2_PRIMARY_KEY_FIELD = 'django.db.models.CharField'


# Password validation
Expand Down
Empty file added tests/__init__.py
Empty file.
1 change: 0 additions & 1 deletion tests/test_primary_key_format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import uuid

import pytest
from django.db import models

from eav.logic.object_pk import get_pk_format
Expand Down
40 changes: 40 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.core.exceptions import ValidationError
from django.forms import Textarea
from django.test import TestCase
from eav.widgets import CSVWidget


class TestCSVWidget(TestCase):
def test_prep_value_string(self):
self._extracted_from_test_prep_value_empty_2("Test Value")

def test_prep_value_list(self):
widget = CSVWidget()
value = ["Value 1", "Value 2", "Value 3"]
self.assertEqual(widget.prep_value(value), "Value 1;Value 2;Value 3")

def test_prep_value_empty(self):
self._extracted_from_test_prep_value_empty_2("")

# TODO Rename this here and in `test_prep_value_string` and `test_prep_value_empty`
def _extracted_from_test_prep_value_empty_2(self, arg0):
widget = CSVWidget()
value = arg0
self.assertEqual(widget.prep_value(value), arg0)

def test_prep_value_invalid(self):
widget = CSVWidget()
value = 123 # An invalid value
with self.assertRaises(ValidationError):
widget.prep_value(value)

def test_render(self):
widget = CSVWidget()
name = "test_field"
value = ["Value 1", "Value 2", "Value 3"]
rendered_widget = widget.render(name, value)
# You can add more specific assertions based on the expected output
self.assertIsInstance(rendered_widget, str)
self.assertIn("Value 1", rendered_widget)
self.assertIn("Value 2", rendered_widget)
self.assertIn("Value 3", rendered_widget)
Loading