#django

/

      • Melamo
        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?
      • toothe
        okay, i need to ind an example of this
      • of django LDAP authentication.
      • like, a full example.
      • jaddison has quit
      • pwnz0r joined the channel
      • michalmo has quit
      • pwnz0r has quit
      • Melamo
        toothe: this looks to be in the ballpark of what I would do myself: https://github.com/etianen/django-python3-ldap
      • jd|2
        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
      • Melamo
        jd|2: this looks relevant to what you are trying to do: http://bytes.com/topic/postgresql/answers/42334...
      • jarshwah has quit
      • 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
        http://www.postgresql.org/message-id/501B1494.9... suggests using a separate counter table.
      • Lobstaman3 has quit
      • Melamo
        jd|2: concurrency is hard :)
      • moldy
        jd|2: are you 110% sure it's a product requirement to never have gaps? what is created first, the physical form or the db record?
      • Melamo
        really hard (to get right)
      • jd|2
        moldy: Physical form
      • moldy: yeah they dont want gap, thats why we dont have option to delete
      • moldy
        jd|2: and how do you map db records to physical forms?
      • heinrich5991 has quit
      • abara joined the channel
      • abara
        supbuds :D
      • jd|2
        Form number are in a sequence, from 0 to 100,000
      • so my objects when created should have same ending sequence
      • mattmcc
        What if someone tears up one of the forms? :P
      • moldy
        jd|2: so the users have to create the objects in the right order?!
      • heinrich5991 joined the channel
      • jd|2
        Melamo: yeah, my life was pretty simple, before concurrency came in
      • moldy
        jd|2: it really sounds like you should just have the user enter the id
      • jd|2: concurrency becomes easy, then
      • lynads has quit
      • jd|2
        mattmcc: thats a likely case, but as I was told that the guy will end up creating a dummy object, they have a format for that
      • mattmcc
        Eh, I'd go with having the user enter the form number.
      • If it's a paper form that's already been printed, that seems by far to be the most straightforward approach.
      • jd|2
        and we have a active flag which is set flase if that object has to be deleted
      • whitesmoke has quit
      • jaddison joined the channel
      • emma
        moldy: i have a very basic knowledge of html, css, and python
      • its not what i do for a living or anything
      • i just really wonder if django could work. I don't know.
      • RicoAlpha joined the channel
      • im so surprised there is nothing quite like wordpress but in python
      • moldy
        emma: there are a number of plogging engines in python. https://wiki.python.org/moin/PythonBlogSoftware
      • jd|2
        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?
      • shawnadelic
      • You can have a look at the URL and Model there
      • mattmcc
        What's the full error?
      • shawnadelic
        NoReverseMatch at /
      • 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
      • Dominee has quit
      • 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