jd|2: that is the same mechanism used by default to generate pkids on rows
josuebrunel joined the channel
moldy
omarek: did you put your alert inside a function that is never called, maybe?
jd|2
Melamo: yes I am using postgres
doismellburning: yeah, I just felt the same
Melamo
jd|2: you may have to drop down to raw sql to take advantage of the sequence data type along with some built-in functions to perhaps do your id generation at the DB level atomically, but that would be the safest most robust way since it's done at the DB level instead of the app level
omarek
moldy: in the first function. I assume it's automatically called if it's in head ?
moldy
omarek: no
caynan joined the channel
you will have to call it through some mechanism
omarek
Okay, back to school.
mattmcc
jd|2: What happens when a record gets deleted?
SirRetnuh joined the channel
zirikili has quit
omarek
moldy: thank you.
jd|2
Melamo: I havn't worked with postgres before this, so dropping down to raw sql I was just avoiding
zirikili joined the channel
mattmcc: There is no interface to delete that object other than the DB level
wowiezowie joined the channel
stole has quit
Melamo
jd|2: the alternative solution is to learn about PG's transaction isolation levels, be willing to up the isolation level to serializable, and be ready to re-try a transaction on failure... not fun, and not a solution I would recommend: http://www.postgresql.org/docs/9.4/static/trans...
elyezer joined the channel
jd|2: I guess the biggest question I haven't asked is: why not just stick with the standard int pk ids for your objects?
Melamo: One of my co-worker warned that in conflict cases there is skip of pk
Xiti joined the channel
marmalodak joined the channel
I mean the entire series skips some 1000 ints
Melamo: Is that true ?
the_rat_ joined the channel
heinrich5991 has quit
b23 has quit
pwnz0r joined the channel
SirRetnuh has quit
mattmcc
Why is gaps in the sequence a problem?
doza joined the channel
ePirat has left the channel
Melamo
jd|2: I don't think that is the case, but I'm not positive. It would be a good question to ask the folks in #postgresql. The default int pkids are generated using sequences. According to the docs (http://www.postgresql.org/docs/9.4/static/sql-c...) it looks like values my be assigned out of order to different sessions if the cache value is set to greater than 1, but I don't see anything about it skipping a
number completely
doza_ has quit
eVRiAL has quit
heinrich5991 joined the channel
SteenJobs joined the channel
the_rat has quit
jd|2
mattmcc: Its a product requirement, as these id's are not only for internal purpose, but the ID is linked to a physical form and the squence will be the mapping
moldy
make a human enter the id then
auto-generate a suggestion that can be overridden
jd|2
moldy: That could be done, but isn't there a reliable way to generate a continuous sequence
moldy
there probably is, but sooner or later, somebody will want to change one of these IDs
omarek
Got it working.
jd|2
Melamo: I read a few cases on stackoverflow as well, and they said sequence gaps are normal
jd|2: it looks like one possible case if a transaction rollback after a sequence has been polled will not decrement the sequence, so you might very well be right
jd|2
Melamo: So what would you suggest ?
migbot joined the channel
Melamo
jd|2: like I said, I would talk to some of the overly smart folks in #postgresql as it sounds like it's a bit more complicated than I initally thought
mattmcc: moldy: Currently I am generating ID's with post_save signals and getting the row_count and as signals are synchronous so, I was wondering wont they lock the table before getting the row count ?
doza_ joined the channel
mattmcc
jd|2: No, that'd be horrible.
jd|2
mattmcc: I am using signals for the first time, so can you please elaborate the horrible part
mattmcc
Locking the table just to get a row count, that destroys concurrency performance.
Postgres works really hard to minimize locks.
migbot has quit
Siecje has quit
doza has quit
Lobstaman3 joined the channel
shawnadelic
Does anyone know how to get the URL for a generic view function?
jd|2
mattmcc: moldy: Melamo: Thanks for everything, I guess manual approach is the only thing I can go with for now.
shawnadelic
I tried naming it, but that doesn't seem to work since it is expecting arguments
moldy
jd|2: if combined with an auto-suggestion, it is the best solution, imho.
mattmcc
shawnadelic: Then you need to provide arguments.
donspaulding joined the channel
jd|2
moldy: yeah, will check that as well :)
mattmcc
E.g, {% url 'pattern-name' arg=foo %}
moldy
jd|2: ask the table for the max number, add 1, and set that in the form's initial. if save() fails because the id was not unique, display an error and have the user enter another one (or do whatever). concurrency solved.
shawnadelic
mattmcc: Okay, but I'm not sure what it needs since it's a ListView and it's basically just doing the query automatically
mattmcc
shawnadelic: Well, what does the urlpattern look like?
Reverse for 'all_articles' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
jd|2
moldy: what if I do the same when saving ?
by overriding the save method
mattmcc
Is that urls.py your root urlconf, or is it being include()'d?
shawnadelic
It's being included
mattmcc
With a namespace, I imagine.
shawnadelic
oh, okay, yeah, I think so
So i need articles:all_articles
pwnz0r has quit
mattmcc: Awesome, that was it, thanks!
I'm pretty new to django
moldy
jd|2: there is a possible race condition.
jd|2: between the max() and the save(), another request could have used up the id.
jd|2
yeah
moldy
jd|2: but you could catch the exception and redisplay the form, i guess, yep
jd|2
moldy: yeah, if there is conflict I can ask user to save again
that way without anyone manually entering the id will be generated and concurrency will not be a probem
Nux17 joined the channel
Nux17
Hey, got this error when using celery + gevent : DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 140372966528768 and this is thread id 72687120.
any ideas where this come from ?
moldy
jd|2: yes, but how do you make sure id matches the one on the paper form?
jd|2
moldy: by allowing to edit it
haha
Melamo
jd|2: something else to consider is explicit locking
jd|2: create a table, where each row is a sequence value. Doing a select for update on the row to take out a lock on the counter row. Now you can safely read and increment it.
Derailed joined the channel
jd|2: I *think* this will be transaction safe as well, as in if your transaction rolls back, your counter increment will also roll back