Skip to content

Instantly share code, notes, and snippets.

@PirosB3
Created March 14, 2014 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PirosB3/9549853 to your computer and use it in GitHub Desktop.
Save PirosB3/9549853 to your computer and use it in GitHub Desktop.
[11:33am] edbaffei left the chat room. (Quit: edbaffei)
[11:41am] bak1an left the chat room. (Quit: Konversation terminated!)
[11:49am] tape-recorder left the chat room. (Remote host closed the connection)
[11:50am] tape-recorder joined the chat room.
[11:53am] maroloccio joined the chat room.
[11:53am] timograham joined the chat room.
[11:53am] edbaffei joined the chat room.
[12:02pm] dfunckt left the chat room.
[12:07pm] dlogs left the chat room. (Remote host closed the connection)
[12:07pm] dlogs joined the chat room.
[12:08pm] dfunckt joined the chat room.
[12:13pm] puntonim left the chat room. (Quit: puntonim)
[12:16pm] mlavin joined the chat room.
[12:18pm] You left the chat by being disconnected from the server.
[1:17pm] You reconnected to the server.
[1:18pm] You rejoined the room.
[1:20pm] tomchristie joined the chat room.
[1:28pm] kanja left the chat room. (Ping timeout: 264 seconds)
[1:31pm] claudep joined the chat room.
[1:31pm] claudep was granted voice by ChanServ.
[2:01pm] bmispelon left the chat room. (Read error: Connection reset by peer)
[2:02pm] bmispelon joined the chat room.
[2:02pm] bmispelon was granted voice by ChanServ.
[2:07pm] dlogs left the chat room. (Remote host closed the connection)
[2:07pm] dlogs joined the chat room.
[2:13pm] puntonim left the chat room. (Quit: puntonim)
[2:13pm] tomchristie left the chat room. (Quit: My MacBook has gone to sleep. ZZZzzz…)
[2:14pm] deryck joined the chat room.
[2:15pm] puntonim_ joined the chat room.
[2:17pm] tomchristie joined the chat room.
[2:23pm] bmispelon left the chat room. (Quit: Leaving)
[2:27pm] maroloccio left the chat room. (Read error: Operation timed out)
[2:29pm] edbaffei left the chat room. (Ping timeout: 240 seconds)
[2:29pm] PirosB3: Hi guys. what are the parts that meta is used most for: modelform and admin only?
[2:29pm] maroloccio joined the chat room.
[2:34pm] FunkyBob: and models
[2:34pm] FunkyBob: didn't think Admin had Meta classes...
[2:36pm] PirosB3: hi FunkyBob doesn't contrib.admin use meta classes for naming convenetions ecc. ?
[2:36pm] PirosB3: or is that all in ModelAdmin?
[2:37pm] FunkyBob: it pulls details from meta...
[2:37pm] FunkyBob: from the models meta
[2:37pm] bmispelon joined the chat room.
[2:37pm] bmispelon was granted voice by ChanServ.
[2:37pm] PirosB3: ok
[2:37pm] PirosB3: FunkyBob: if you were to refactor meta, what would you be looking for?
[2:39pm] FunkyBob: why would I refactor meta? what's wrong with it?
[2:39pm] PirosB3: it's too messy
[2:39pm] FunkyBob: in what way?
[2:39pm] PirosB3: I am slowly understanding that there is some refactoring to be done
[2:39pm] FunkyBob: all this vagueness isn't getting us anywhere
[2:40pm] PirosB3: ok so
[2:40pm] PirosB3: models/options.py
[2:41pm] PirosB3: I think it could be more modular
[2:41pm] FunkyBob: you're really not helping your case
[2:41pm] PirosB3: functions are very long, could be spilt up into smaller for readability
[2:42pm] PirosB3: some bits I do not like, like altering the dictionaries
[2:42pm] FunkyBob: altering which dictionaries? and why don't you like them?
[2:42pm] PirosB3: if name.startswith('_'):
[2:42pm] PirosB3: del meta_attrs[name]
[2:43pm] PirosB3: where meta_attrs is meta_attrs = self.meta.__dict__.copy()
[2:43pm] PirosB3: wouldn't it be better to override meta in some way, instead of cloning it?
[2:43pm] PirosB3: also, many of the functions contain loads of logic
[2:44pm] PirosB3: there is a lot of complexity
[2:44pm] PirosB3: complexity == more bugs
[2:44pm] PirosB3: said this, I am unsure of where to start and if I am looking correctly. For this reason I am asking you
[2:49pm] jarshwah: PirosB3: I think the original proposal for formalising meta was to have a well defined API that can be exposed publicly
[2:49pm] jarshwah: at the moment meta is private
[2:50pm] jarshwah: but lots of users access it.. it's kind of a secret that everyone knows about, but django just closes its eyes and pretends you aren't accessing it
[2:50pm] jarshwah: the idea isn't really to clean it up as far as I'm aware
[2:50pm] PirosB3: ok
[2:50pm] jarshwah: but coming up with a stable set of properties and methods that could be useful
[2:50pm] jarshwah: and locking them down
[2:50pm] PirosB3: jarshwah: I have been thinking about the implenentation
[2:51pm] PirosB3: in order to provide a public interface, there needs to be a simple way of using it
[2:51pm] jarshwah: so what I'd suggest, is looking at how meta is used currently.. and coming up with a broad set of "features"
[2:52pm] PirosB3: jarshwah: what do you mean with features?
[2:52pm] jarshwah: PirosB3: I'd take a step further back
[2:52pm] jarshwah: and ask what is it used for
[2:52pm] dfunckt: FWIW, i'd start by renaming the methods in a consistent way, get_fields_* methods especially are a mess
[2:52pm] PirosB3: it's by other components to gain further information about the model
[2:53pm] PirosB3: introspection
[2:53pm] jarshwah: mmm, but which information? and can you generalise particular methods or properties
[2:53pm] PirosB3: dfunckt: thanks for the hint
[2:54pm] PirosB3: jarshwah: I see it that meta deals with too much stuff
[2:54pm] PirosB3: we could break that down into smaller components, overridable
[2:54pm] dfunckt: PirosB3: there's also this ugly mess of cached properties, created for efficiency at first access
[2:54pm] kanja joined the chat room.
[2:54pm] PirosB3: and then have some sort of "chain", where it is easy to add custom behavour
[2:54pm] jarshwah: perhaps, I haven't looked into meta that much
[2:55pm] PirosB3: dfunckt: how does that work? it that the lazy loading?
[2:55pm] dfunckt: yes
[2:55pm] PirosB3: it's in meta?
[2:55pm] dfunckt: https://github.com/django/django/blob/master/django/db/models/options.py#L309
[2:55pm] dfunckt: for example ^
[2:56pm] dfunckt: it's good they're lazy, i'm not opposing that
[2:56pm] PirosB3: wow it does a lot
[2:56pm] dfunckt: i'm just saying that they're named rather inconsistently
[2:56pm] PirosB3: what about having more components that interact together
[2:57pm] PirosB3: like have a "Cacheable" meta class
[2:57pm] PirosB3: and a "Ordering" metaclass
[2:57pm] PirosB3: and then these get composed together
[2:57pm] PirosB3: or am I going completely off track
[2:58pm] dfunckt: not sure you can diverge a lot from what's in there, for backwards-compatibility
[2:58pm] dfunckt: you'd need to define what meta is used for
[2:58pm] dfunckt: access to fields for one
[2:58pm] dfunckt: user-defined options that django makes use as a second
[2:59pm] dfunckt: if you attempted to rename the methods you'd see patterns of use emerge
[2:59pm] dfunckt: then, you could refactor, sure
[2:59pm] PirosB3: dfunckt: but is this task only refactoring, or is it also "restructuring"?
[3:00pm] andrewgodwin joined the chat room.
[3:00pm] andrewgodwin was granted voice by ChanServ.
[3:00pm] jarshwah: get_all_related_objects_with_model .. what a mouthful
[3:00pm] dfunckt: AFAIK it is to provide a consistent public api
[3:01pm] PirosB3: but to provide a consistent public API, we will most probably lose backwards compatibility
[3:01pm] dfunckt: jarshwah: get_all_related_m2m_objects_with_model that's a lot better
[3:01pm] dfunckt: PirosB3: i think it's a precondition to provide a path to upgrade
[3:01pm] jarshwah: PirosB3: you can deprecate old methods I guess, and have them call the new public API
[3:02pm] shaib joined the chat room.
[3:02pm] shaib was granted voice by ChanServ.
[3:02pm] PirosB3: but still
[3:02pm] dfunckt: a third role for options is for accessing parent models
[3:03pm] PirosB3: how do I know what methods people are using, as it's never been documented, I need to assume that all the old methods are being used
[3:03pm] PirosB3: dfunckt: through abstract?
[3:03pm] dfunckt: most of field related methods are used
[3:04pm] dfunckt: not only, for multi-table inhertance in general
[3:04pm] kmtracey left the chat room. (Ping timeout: 240 seconds)
[3:04pm] PirosB3: so all those get_field*
[3:04pm] dfunckt: yes
[3:04pm] dfunckt: i wouldn't care for the _* methods
[3:05pm] dfunckt: these are private-private i guess
[3:05pm] PirosB3: one part I do not understand
[3:05pm] PirosB3: lol
[3:05pm] PirosB3: So, for example, you could build a wrapper around a NoSQL store, or around an LDAP or email store, that *looked* like a Django model from the outside. This means you could view your NoSQL data, or LDAP records, or emails in Admin without needing to go through a SQL database.
[3:05pm] PirosB3: meta docent deal with the actual "transaction"
[3:05pm] PirosB3: dosent
[3:06pm] dfunckt: yes, not at all
[3:06pm] dfunckt: these are in db.models.query and below
[3:06pm] PirosB3: so what does this part mean?
[3:06pm] dfunckt: meta is for defining the model, its fields, any options, handle inheritance etc
[3:07pm] dlogs left the chat room. (Remote host closed the connection)
[3:07pm] dfunckt: and also for related managers
[3:07pm] dlogs joined the chat room.
[3:08pm] PirosB3: related managers?
[3:09pm] PirosB3: ah ok
[3:09pm] PirosB3: you mean with meta you can define a manager?
[3:09pm] dfunckt: no, sorry i confused you
[3:10pm] dfunckt: but you go through meta.contribute_to_class to add anything to the model, including managers
[3:11pm] dfunckt: all in all, i'm not an expert in refactoring, but i'd start small, and grow incrementally, combining, deleting, adding code
[3:11pm] dfunckt: tht's why i initially suggested you start by renaming methods, to become familiar
[3:11pm] PirosB3: ok so I should start by renaming methods
[3:12pm] PirosB3: what should I precisely look at
[3:13pm] dfunckt: not sure, all these *_with_model methods, or rename m2m everywhere with many_to_many, things like that
[3:13pm] PirosB3: ok
[3:13pm] PirosB3: where are these methods actually called
[3:13pm] dfunckt: all over the place
[3:13pm] PirosB3: are there some specific parts of the code that I should have a look at?
[3:14pm] PirosB3: dfunckt: exactly
[3:14pm] PirosB3: lol
[3:14pm] dfunckt: but most likely in models.query
[3:14pm] PirosB3: from what I understand
[3:14pm] PirosB3: meta started as something small, and then grew exponentially
[3:14pm] PirosB3: and it has never been refactored in something usable
[3:15pm] dfunckt: i guess so
[3:15pm] PirosB3: so basically you have all parts of code storing and retrieving from meta
[3:15pm] dfunckt: like most of open-source projects
[3:15pm] PirosB3:
[3:15pm] dfunckt: a cleaned up meta would make a lot sense
[3:16pm] PirosB3: also, any tickets you would suggest me to have a look at?
[3:16pm] dfunckt: it could then grow a lot better
[3:16pm] dfunckt: ah, don't know at all
[3:16pm] esauro left the chat room. (Quit: Saliendo)
[3:19pm] PirosB3: ok
[3:19pm] PirosB3: thanks
[3:19pm] PirosB3: so I will start by renaming some parts, and seeing how everything works together
[3:19pm] PirosB3: I will try to identify common patterns
[3:19pm] PirosB3: these will give me more ideas for a refactor
[3:20pm] PirosB3: also, are there any test cases that could help me understand more?
@PirosB3
Copy link
Author

PirosB3 commented Mar 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment