doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.86k stars 352 forks source link

Fixed a bug related to django4 foreign key lookups #647

Open HardlyForeal opened 1 year ago

HardlyForeal commented 1 year ago

Previous versions of django ran a foreign key lookup with a const (1) parameter in the column list. Django 4 changed that to a parameterized value and pass the parameter value 1. I have created a new token type to hold the aliased paramaterized value. SQLConstParameterizedIdentifier is subclassed from SQLConstIdentifier, and the original functionality is broken out into SQLConstIntIdentifier. This should allow anything that was using isinstanceof for SQLConstIdentifier to still work and allows expansion to other non-int constants. A test case has been added for the django 4 select statement. Closes #630 Closes #634

HardlyForeal commented 1 year ago

Issue #630 was closed by the poster with the comment that they "fixed" it by reverting back to a prior django version. Other postings I've seen indicate that djongo is supposed to support the latest django version, so that issue should really still be open, and would be fixed by this pr. As far as I can tell, this is an issue with every foreign key relationship in the latest django due to changes in the sql it generates.

ghpkishore commented 1 year ago

@HardlyForeal Thanks! I had faced the same bug and used your commit files to update my local djongo files. Works like a charm now.

pekosoG commented 1 year ago

Im facing exactly the same issue, @ghpkishore would you please share how did you manage to get it working? Did you use a monkey-patching in those methods?

ghpkishore commented 1 year ago

What ever files are present in this commit, I updated the files in my system with those. That worked. You can think of it as monkey-patching, but I changed the source code in the downloaded repo itself.

deviantfero commented 1 year ago

Is this going to be merged soon?

Pansuria-Shrey commented 1 year ago

Will it get merge anytime soon?

phoenixsite commented 11 months ago

Still working perfectly in Django 4.2.3 and the latest uploaded version of djongo. I had the exists() issue and also the validation of duplicate User usernames in the DB wasn't working. Thank you so much!

ELDiablO59152 commented 9 months ago

Thank you very much ! Please merge this fix

pimuzzo commented 1 month ago

@nesdis please can you take a look on this?