#django

/

      • moldy
        Knyght: could be that line 6 is not True when it should be, for example
      • jMyles
        subho: This is something of a major outstanding problem in python web asynchrony.
      • moldy
        Knyght: btw, are you trying to hand out unique passwords?
      • Knyght
        moldy: kinda, they're used per game, so ayone with the password can join by like tapping it into their phone or whatever. They get rescinded when the game starts so collisions should be rare, but I still want to handle the case
      • moldy
        Knyght: probably easier and better to use an identifier plus a password instead of trying to make the password be both
      • Knyght: as for the test, the problem could be in the factory...
      • Knyght
        moldy: I'm aware, but I want to make it as seemless as possible
      • hmm that's a thought
      • synapps has quit
      • hmm, don't think so, at least I'm not doing anything special with it
      • subho
        jMyles: actually yes celery process job pool. :( spent half of my day trying various solution.
      • mdiarra joined the channel
      • moldy
        Knyght: look at the traceback...
      • Knyght
        hmm
      • moldy
        apparently faker is calling random.choice, which is your mock
      • Knyght
        oh, ffff
      • thanks :/
      • I would probably not have caught that
      • moldy
        you're welcome
      • rams3377 joined the channel
      • Knyght
        guess that can be static anyway
      • or I can just hardcode it for that test I guess
      • emperorcezar has left the channel
      • it_dude joined the channel
      • jMyles
        subho: What type of job are you trying to do? Is it CPU-bound?
      • efstone has quit
      • Nizumzen joined the channel
      • subho
        jMyles, i wanted to make django signals async. so on signal a task(insertion to two db) is added to celery .
      • gerbyzation has quit
      • ubuntu_aze joined the channel
      • jMyles
        subho: So, you can probably still do that with Celery by passing it a function that's top-level in the module instead of an instance method.
      • areski joined the channel
      • tiagoboldt joined the channel
      • If, on the other hand, you need the context of the instance method, and your task is very CPU-light, which it sounds like it is, then (and this is sometimes heresy around these parts) you can use a thread.
      • subho: Twisted handles this situation very nicely and with less overhead than Celery / RabbitMQ.
      • subho: Here's an API for doing that with hendrix: http://hendrix.readthedocs.org/en/latest/crosst...
      • dodobas
        danielsh: take a look at https://docs.djangoproject.com/en/1.8/ref/model... ... select param
      • it_dude has quit
      • dang`r`us
        danielsh, well, this works: Host.objects.annotate(is_special=ExpressionWrapper(Case(When(user_id=152,then=1), When(~Q(user_id=152), then=0)), output_field=IntegerField()))[0].is_special
      • danielsh, but it's horribly contorted.
      • subho
        jMyles, ahh! nice! :) let me explore it. :D Thanks!
      • dang`r`us
        danielsh, probably better to throw some rawer SQL in there, lemme see ....
      • danielsh, (my Host is your Foo and my user_id is your bar_id)
      • dodobas
        dang`r`us: wtf ? :)
      • jMyles
        subho: Just make sure that your signal hook is not CPU-bound; otherwise using a thread will cause the worker performance to drop off a cliff
      • dang`r`us
        dodobas, yeah ... that's what I thought too.
      • mehola has quit
      • enkrypt has quit
      • subho
        jMyles, :P lol. i had that falling off the cliff experience when i used ffmpeg in a thread once.
      • dang`r`us
        danielsh, this maps to True/False not 1/0 but is way more readable: Host.objects.annotate(is_special=RawSQL("user_id=%s", (152,)))
      • jMyles
        subho: Yeah. It'll getcha. But threads are incredibly performant for network/IO bound tasks. You just need to be a lot more careful and conscientious about the intentions of your code, and that goes for many aspects of async, not just performance.
      • gerbyzation joined the channel
      • dang`r`us
        dodobas, if you can make my first example simpler, please tell me, I'm curious (basically: annotate a QS so that is_special is 1 when o.user_id=152, and 0 otherwise)
      • efstone joined the channel
      • jMyles
        subho: We're working on a way to pass crosstown_traffic to a separate child process. A... VoodooChild process. :-)
      • subho
        jMyles, cool!
      • efstone
        hey, everyone.
      • tiagoboldt has quit
      • I have a quick question: why are some field types not created as columns in the corresponding db table? I'm on django 1.83 using MySQL 5.5.4
      • danielsh
        dang`r`us, dodobas: thanks! All those solutions are pretty much equivalent, but .extra(select=...) is tastiest to me.
      • drichards joined the channel
      • subho
        efstone, tried makemigrate and migrate command?
      • efstone
        indeed
      • on two separate systems
      • dang`r`us
        danielsh, I did not know about extra and indeed it does seem your best fit
      • dodobas, did not see you pointing towards extra ... it's clear now.
      • but yeah, if one wants to avoid raw sql, there's still my first abomination....
      • danielsh
        dang`r`us, your ExpressionWrapper does have the advantage of being immune to sql injection, though.
      • dang`r`us
        danielsh, wheeee :V
      • danielsh
        Not that much injection can be done with integers...
      • dang`r`us
        (I suppose removing all non-digit characters from your parameter via regex or sth does the trick just as well)
      • danielsh
        My parameter is a python integer, actually.
      • dang`r`us
        even better
      • danielsh
        :)
      • Hairy joined the channel
      • dodobas
        danielsh: you can pass parameters to extra, which will be checked for 'sql injection' attacks
      • efstone
        FYI, there is a pattern regarding the model fields that do not become part of the table: they are URLfield and DateTimeField
      • Hairy has quit
      • dang`r`us
        efstone, maybe you need to makemigrations and run migrate
      • I can assure you those fields are not broken.
      • efstone
        I have indeed been using makemigrations and migrate. I've also examined the sqlmigrations SQL and there's no mention of those fields at all in the SQL
      • enkrypt joined the channel
      • danielsh
        dodobas, thanks for pointing that out - hadn't read that far down the linked doc yet.
      • (trying to multitask)
      • Hairy joined the channel
      • pilva joined the channel
      • sanketdg joined the channel
      • gerbyzation has quit
      • jaddison has quit
      • brat197 has quit
      • subleq has quit
      • shangxiao joined the channel
      • infinitesum joined the channel
      • cestlavie has quit
      • infinitesum
        I have two models for the same underlying Postgres table. Do I need to add db_index=True to a given field in both the models, or only one of them?
      • cestlavie joined the channel
      • shadowbeast joined the channel
      • Xard joined the channel
      • doismellburning
        infinitesum: that sounds terrifying; why?
      • boxbeatsy joined the channel
      • infinitesum
        doismellburning: There are basically a bunch of fields on my model that I need to store, but that I don’t want to return to the users when rendering JSON responses. So I created a second set of ‘ReadOnly’ models with managed=False, so that way I’m not retrieving unnecessary fields or risking accidently leaking non-public information to users
      • theslow1 joined the channel
      • vdboor joined the channel
      • doismellburning: I think I saw in the docs somewhere that if you’re going to be doing that on a one-off basis, just use deferred, but if you’re going to do it on a regular basis then you can just have alternate models that are missing some of the fields on the managed model
      • doismellburning
        infinitesum: right; are you using DRF at all?
      • infinitesum
        doismellburning: Yes, I am
      • doismellburning
        infinitesum: consider using DRF and using different Serializers
      • not different models
      • bmac joined the channel
      • theother1 joined the channel
      • infinitesum
        doismellburning: Is there a good way then to not retrieve the db fields I don’t actually need, rather than just not serializing them after they’re retrieved?
      • subleq joined the channel
      • ehmatthes joined the channel
      • doismellburning
        infinitesum: why does that matter?
      • maryokhin joined the channel
      • nimomo joined the channel
      • Audioburn joined the channel
      • infinitesum
        doismellburning: Really only for query speed
      • bmac has quit
      • doismellburning
        infinitesum: your bottleneck is data transfer?
      • vdboor has quit
      • subleq has quit
      • DarkSector
        How do I temporary hold data fetched by celery till the client asks for it?
      • *temporarily
      • nimomo has quit
      • rdorgueil joined the channel
      • infinitesum
        doismellburning: I haven’t launched yet so we have yet to benchmark anything
      • : doismellburning: But db performance is what I’m most worried about… For reference this is just for the one table used to generate the news feed on a social network type site
      • rdorgueil has quit
      • rdorgueil joined the channel
      • tobias47n9e__ joined the channel
      • thepreacher has quit
      • bmac joined the channel
      • flobin has quit
      • szacun has quit
      • tobias47n9e_ has quit
      • citizen-stig joined the channel
      • jwhitmore joined the channel
      • Hairy joined the channel
      • acogneau has left the channel
      • tindus has quit
      • rain0r joined the channel
      • josuebrunel joined the channel
      • rdorgueil has quit
      • rdorgueil joined the channel
      • theother1 has quit
      • ojdo has quit
      • doismellburning: I looked into it, I think I’m just going to use an abstract table so that was I still have both a managed and unmanaged table, but I don’t need to repeat all the field definitions in both places
      • gerbyzation joined the channel
      • maryokhin has quit