Monday, October 22, 2018

RE: Creating seperate unique ids within the same table

I am curious why you think it is anti-practice to expose primary keys for user-visible purposes.

My URLs all have the PK to the object in them, and any advanced user would be able to "reverse engineer" a URL if they guess the PK of an object—and that's okay.

Even Django tutorials suggest using the PK in the URL of an object.

I'm just curious.

 

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of bill.torcaso.oxfam@gmail.com
Sent: Monday, October 22, 2018 10:20 AM
To: Django users
Subject: Re: Creating seperate unique ids within the same table

 

 

Joel,

 

I completely agree that UUIDs are not memorable.

 

I still think you would be well-served to make a UUID the basis for uniquely defining a person.  If you want to further add a short name, you could make an object class that has a UUID and, say, an 8-digit number.  If you assert that the two are unique together, you will get a database-level guarantee of uniqueness at creation-time.

This is just an opinion, but I think it an anti-practice to expose a primary key for any user-visible purpose.

If you don't like UUID's for your purpose, you might consider the random number generator in PyCrypto.

On Monday, October 22, 2018 at 10:20:02 AM UTC-4, Joel wrote:

Thank you Bill. I had a look at UUIDs. One of the important criteria I
had was that these IDs should be easily memorable. Unfortunately UUIDs
are not memorable, being too long to remember. :(

Sincerely yours,

Joel G Mathew


On Mon, 22 Oct 2018 at 19:40, <bill.torc...@gmail.com> wrote:
>
> Hello all,
>
> The previous discussion shows a method that will work.  but I think it has disadvantages, and I want to suggest  another approach.
>
> The disadvantage of using a primary key from a table, any table, is that you are committing to that table and that primary key for all eternity.   this has consequences for migration to another system , for merging in data from an external system, among others.
>
> Joel, if I understand your situation, you have a "thing", an individual human being, and you need a permanent, unique identifier for that "thing".  The identifier should not be an implementation detail of your current code, but should be robust, sharable, and resilient in the face of evolving software.
>
> I faced a similar situation with digital assets that are photos and videos.  We share photos and videos across several related sites, but we don't want to duplicate the asset for each site.
>
> My solution is to generate a UUID, a Universally Unique IDentifier,  when creating the "thing" - see python 3 at https://docs.python.org/3/library/uuid.html. or python 2 at https://docs.python.org/2/library/uuid.html.
>
> A Universally Unique IDentifier is guaranteed not to collide with any other UUID, and so independent systems can generate one at any time - no need to coordinate with a central database or across separate servers.
>
> A UUID is robust in the face of name changes - such as a maiden name becoming a married name.
>
> I would recommend a UUID over exposing a primary key, hands down, all the time, no exceptions.
>
> --  Bill
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8bcbd562-5bb8-49f3-b1ad-1b73ff62d840%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eb95ee38-160e-4acb-b966-9b7f3ddd6c75%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment