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

ValidationError exception on UUID #299

Closed
bedros opened this issue Jul 5, 2017 · 8 comments
Closed

ValidationError exception on UUID #299

bedros opened this issue Jul 5, 2017 · 8 comments

Comments

@bedros
Copy link

bedros commented Jul 5, 2017

my model is as follows

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255)
description = models.CharField(max_length=2047, blank=True, null=True)
case_number = models.CharField(max_length=255, blank=True, null=True)
about_person = models.ManyToManyField('Person', blank=True, related_name="about_person_case")
history = HistoricalRecords()

when I click on history in admin I get error page with following

["Content of description field' is not a valid UUID."]

why it takes content of description as the UUID?

my str is not simple,

def __str__(self): return str(self.name + " about " + self.about_person)

if I change str to
def __str__(self): return str(self.name)

problem goes away, but I need str to return name and about person

@bedros
Copy link
Author

bedros commented Jul 5, 2017

actually, after changing str to return name, in simple history admin page, under object column, I get "None" not the value of name

@bedros
Copy link
Author

bedros commented Jul 5, 2017

after adding print(self.pk) and print(self.id) inside str function, I get the content value of the field description printed for self.pk and self.id

@bedros
Copy link
Author

bedros commented Jul 5, 2017

I did not mention that I have modified_on and modified_by fields for simplicity, and I added those fields to excluded_fields

however, once I removed the excluded_fields from HistoricalRecords I got it to work fine with no problems.

@macro1
Copy link
Collaborator

macro1 commented Jul 5, 2017

I'm not sure I can speak directly to the issues you're seeing, but I would suggest you limit your string representations to fields on the model itself, to avoid extra DB queries.

Since about_person is a ManyToManyField def __str__(self): return str(self.name + " about " + self.about_person) will attempt to generate a string representation of the set of related models, which may require a database query.

String representations should be limited to fields on the table associated with the model that we can expect will be already present in memory at the time __str__() is called.

So two comments here I guess, but they're really not related to simple_history, as the way you're customizing __str__() makes me think there's more going on.

If the requirement is that the admin display information about both the model with name (Case?) and information in the related about_person fields (On Person.), I suggest configuring the admin to make that more detailed description, rather than assuming that all parts of your application will be willing to make those additional database calls.

My second comment is on whether you actually want about_person to be a ManyToManyField. It sounds like you might just want a normal ForeignKey. Can a specific case be related to more than one person?

@bedros
Copy link
Author

bedros commented Jul 5, 2017

Marco, thanks for raising valid points.

a user may create a case called "Documents about John Smith" however, since the user already entered in the case, about a person "John Smith" the case name has redundancy. it would be better to name the case "Documents" and then the display name of case is "Documents about John Smith"

for the second part, I tried to make it as much flexible as possible, however, there are rare cases where we need M2M in about fields, and most importantly, it would be hard to switch from M2M to FK (for performance reasons) if users already used multiple entries in the m2m field. we can always switch from FK to M2M in future if we need it.

for using multiple DB queries in __str__ I find it a better user experience not having to enter "about some person" in the name of the case, since the case already has that info, and we can fix DB performance from this with read only DB slaves.

@rossmechanic
Copy link
Collaborator

@bedros did you ever find a fix for this?

@jeking3
Copy link
Contributor

jeking3 commented Sep 16, 2021

ManyToManyField is not supported; there are numerous issues about it here, like #399.

@ddabble
Copy link
Member

ddabble commented Oct 22, 2023

Assuming that the issue is resolved now that support for M2M fields has been added. Please reopen if it's still not resolved.

@ddabble ddabble closed this as completed Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants